Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DateTimeItem doesn't validate the value as appose to DateItem

    Hello,

    I'm using SmartClient_v91p_2014-03-23_PowerEdition.

    When I use this code and enter invalid data the validation error appear only in the DateItem and not in the DateTimeItem, why?

    Code:
    isc.VLayout.create({
            ID:"mainPageLayout",
            autoDraw:true, // This is the only place to set autoDraw true
            width:"100%",
            height:"100%",
            members:[
    
              isc.DynamicForm.create({
    
                ID:'form1',
    
                titleAlign:"left",
    
                validateOnExit:true,
    
                fields:[
    
                  { /* Date */
    
                    name:"date",
    
                    title:"Date",
    
                    editorType:"date",
    
                    useTextField:true
    
                  },
    
                  { /* Date Time */
    
                    name:"dateTime",
    
                    title:"Date Time",
    
                    editorType:"dateTime",
    
                    useTextField:true
    
                  }
                ]
              })
    
            ]
    
          });

    #2
    I manage to get it working when adding validator isDate (which wasn't in the validator types documentation)

    but now I'm having troubles with dateFormatter. This code will always state there is invalid date although choosing the date from the picker.

    Code:
    { /* Date */
    
              name:"date",
    
              title:"Date",
    
              editorType:"date",
    
              dateFormatter:"dd/MM/yyyy",
    
              inputFormat:"dd/MM/yyyy",
    
              validators:[
    
                {type:"isDate"}
    
              ],
    
              useTextField:true
    
            },
    
            { /* Date Time */
    
              name:"dateTime",
    
              title:"Date Time",
    
              editorType:"dateTime",
    
              dateFormatter:"dd/MM/yyyy HH:mm",
    
              inputFormat:"dd/MM/yyyy HH:mm",
    
              validators:[
    
                {type:"isDate"}
    
              ],
    
              useTextField:true
    
            },

    Comment


      #3
      Well I manage to figure out what is the problem, the inputFormat should be 'DMY'. Now I have another problem.
      I'm trying to use two date items which the first date item must be at least the date of the second date item, this code doesn't work:

      Code:
      { /* Date */
      
                name:"date",
      
                title:"Date",
      
                editorType:"date",
      
                dateFormatter:"dd/MM/yyyy",
      
                inputFormat: "DMY",
      
                validators:[
      
                  {type:"isDate"},
                  {type:"dateRange", min:"form1.getItem('dateTime').getValue()"}
      
                ],
      
                useTextField:true
      
              },
      
              { /* Date Time */
      
                name:"dateTime",
      
                title:"Date Time",
      
                editorType:"dateTime",
      
                dateFormatter:"dd/MM/yyyy HH:mm",
      
                inputFormat: "DMY Hm",
      
                validators:[
      
                  {type:"isDate"}
      
                ],
      
                useTextField:true
      
              }
      is there an option to do this?
      Last edited by RotemMSP; 2 Apr 2014, 05:44.

      Comment


        #4
        Again, couldn't wait for your answer :)

        I did it by creating a custom validator and registering it with 'Validator.addValidatorDefinition'

        Comment


          #5
          Declare type:"date" or type:"datetime" on these fields and remove your editorType setting - it's unnecessary.

          Note that if you have a future reason to use editorType, it should be the full name of a FormItem class. So for example "DateTimeItem", not "dateTime" as you had it.

          This also removes the need for an "isDate" validator. This validator isn't documented because you would never need to declare it explicitly.

          To do validation for a specific form, just declare a validator of type:"custom" and provide a condition function. You don't have to actually use Validator.addValidatorDefinition() unless you are trying to define a validator that is reusable across different forms.

          Finally, consider using a serverCustom validator either instead or in addition to your type:"custom" validator if this validation needs to be enforced server-side.

          Comment


            #6
            Great, thank you.

            Comment

            Working...
            X