Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63855

Support 'min' and 'max' values in the <f:number> tag

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • None
    • 2.286 released 30 Mar 2021, 2.289.1

      The <f:number> tag should support the 'min' and 'max' properties that <input type="number"> supports.

      This will provide a modicum of client-side validation for constrained number fields, and limit the stepper buttons in the configuration UI, giving the user a stronger hint about the range of acceptable values.

      Example:

       

      <f:entry field="foo">
        <f:number min="10" max="100" />
      </f:entry>

      Will be rendered into an input tag like:

      <input type="number" ...other properties... min="10" max="100">
      

          [JENKINS-63855] Support 'min' and 'max' values in the <f:number> tag

          Benny Cheng added a comment -

          Hello Chris, your idea is great. I tried to add "min" and "max" attribute to the "input" element, I found it didn't work. After doing some research, I found that the stepper buttons and "input" element were not wrapped by "form" element.

          It seems that if you'd like to do validation to the field, adding "min" and "max" attributes isn't the best solution to do it.

          Benny Cheng added a comment - Hello Chris, your idea is great. I tried to add "min" and "max" attribute to the "input" element, I found it didn't work. After doing some research, I found that the stepper buttons and "input" element were not wrapped by "form" element. It seems that if you'd like to do validation to the field, adding "min" and "max" attributes isn't the best solution to do it.

          Chris Kilding added a comment -

          Hi Benny, appreciate that client-side validation is limited. This is why I'd love to see javax.validation annotations available for use on plugin configuration classes one day, so that validations could be defined in a single place (on the fields they constrain) and guaranteed to apply everywhere the config class is used. I guess in that scenario we could read the annotations and set the client-side min/max attributes from them, when rendering the Jelly templates. I believe there was some work done on that a couple of years ago but it wasn't completed.

          Chris Kilding added a comment - Hi Benny, appreciate that client-side validation is limited. This is why I'd love to see javax.validation annotations available for use on plugin configuration classes one day, so that validations could be defined in a single place (on the fields they constrain) and guaranteed to apply everywhere the config class is used. I guess in that scenario we could read the annotations and set the client-side min/max attributes from them, when rendering the Jelly templates. I believe there was some work done on that a couple of years ago but it wasn't completed.

          Benny Cheng added a comment -

          I see.

          Benny Cheng added a comment - I see.

          Jesse Glick added a comment -

          Note that you currently do e.g. clazz="positive-number".

          Jesse Glick added a comment - Note that you currently do e.g. clazz="positive-number" .

          Benny Cheng added a comment -

          HI Chris, I've made a min/max validator. It can show error message when input value is not in the given range.

          I made this validator for the <input> whose clazz is "number", "number-required",  "non-negative-number-required", "positive-number", "positive-number-required". You have to add these clazz to enable the min/max validator. e.g. <f:number clazz="positive-number" min="5" max="70">

          But if the number is out of range, it won't limit the stepper buttons.

          Just check the demo and check if the content of the error message is good or bad.

          If it's ok, I'll make a pull request.

          Benny Cheng added a comment - HI Chris, I've made a min/max validator. It can show error message when input value is not in the given range. I made this validator for the <input> whose clazz is "number", "number-required",  "non-negative-number-required", "positive-number", "positive-number-required". You have to add these clazz to enable the min/max validator. e.g. <f:number clazz="positive-number" min="5" max="70"> But if the number is out of range, it won't limit the stepper buttons. Just check the demo and check if the content of the error message is good or bad. If it's ok, I'll make a pull request.

          Chris Kilding added a comment -

          Hi Benny, the demo looks good.

          When you say there's a validator, do you mean there is also a javax.validation based validator on the server side, or is this only a client-side validator?

          Chris Kilding added a comment - Hi Benny, the demo looks good. When you say there's a validator, do you mean there is also a javax.validation based validator on the server side, or is this only a client-side validator?

          Benny Cheng added a comment -

          I found that we can make a validator at the client side, so I made it at client side.

          Benny Cheng added a comment - I found that we can make a validator at the client side, so I made it at client side.

            benebsiny Benny Cheng
            chriskilding Chris Kilding
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: