Announcement

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

    Date Validation

    Isomorphic,

    I am having 4 select Items.

    From Month(values are like Jan, Feb, Mar etc..)
    From Year(Values are like 2008,2009 etc..)
    To Month(values are like Jan, Feb, Mar etc..)
    To Year(Values are like 2008,2009 etc..)

    I need to validate the selected entries based on click on a button. I thought of using DateRangeValidator. But how can i associate this validator? to which component i need to associate?(Like to which component i need to set this validator)

    we are not using datepicker because our own reasons.. Given this scenario, how can we validate user selection.

    Please give me some clue.

    Thanks,
    Yathish

    #2
    If these values are ultimately combined into a date or datetime value and then saved to a DataSource field of type date or datetime, you can declare a DateRangeValidator on that field and validation will be enforced on the server.

    However presumably you are looking for a way to get validation icons shown next to the FormItems you are using for inputting this individual month and year values - for this you'll need to just add your own CustomValidator with whatever logic you need.

    Comment


      #3
      Actually to elaborate a little further - say you had a CanvasItem that is used with a field of type date or datetime. That CanvasItem might have a DynamicForm with several individual FormItems for inputting just month or year. If you gather together the values from the individual FormItems, create a Date instance and use CanvasItem.storeValue() to make this the value for the CanvasItem, then you can place a DateRangeValidator on the CanvasItem and it will cause errors to show up next to the CanvasItem as a whole when it fails (but not next to the individual FormItems for picking month or year).

      Comment


        #4
        Date Validation

        How do you add a DynamicForm to a CanvasItem?

        I have 2 TextItems, 1 for the hours/minutes/seconds, 1 for the month/day/year.

        I would like to use a DateRangeValidator.

        Comment


          #5
          A DynamicForm is a Canvas.

          A CanvasItem can hold any Canvas.

          Comment


            #6
            Date Validation

            I get: com.google.gwt.core.client.JavaScriptException: (TypeError): self.storeValue is not a function

            validateCanvas = new CanvasItem();
            DynamicForm validateForm = new DynamicForm();
            validateForm.setFields(time, dmy);
            valiodateCanvas.setCanvas(validateForm);
            validateValidator = new DateRangeValidator();
            validateCanvas.setValidators(validateValidator);

            ...
            DateTimeFormat dateFormat = DateTimeFormat.getFormat("HH:mm:ss MM/dd/yyyy");
            Date newTime = dateFormat.parse(layout.getTime().getDisplayValue() + " " + layout.getDmy().getDisplayValue());

            layout.getValidateCanvas().storeValue(newTime);

            Comment


              #7
              We would suggest starting by looking into getValidateCanvas() - that's not our method, so we can't tell you why it's broken :)

              See also the docs for setEditorType() and note the special rules for correctly retrieving FormItems in event handlers. You can look at the CanvasItem samples in the Showcase for correct sample code.

              Comment


                #8
                Date Validation

                getValidateCanvas() simply returns the CanvasItem.

                Comment


                  #9
                  Good to know. Just in case it's not clear what the next step is:

                  See also the docs for setEditorType() and note the special rules for correctly retrieving FormItems in event handlers. You can look at the CanvasItem samples in the Showcase for correct sample code.

                  Comment

                  Working...
                  X