Announcement

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

    setting endDate to current date.

    Hi,

    I am trying to implement endDate for a dateTime field but its not working,

    Can you please let me know what is wrong with my code.
    I need max date should be current, user is not allowed to enter date more than current date or future date.

    Here is the dataSource declaration.


    <DataSource>
    <ID>estData</ID>
    <title>Attach</title>
    <recordName>Attach</recordName>
    <serverType>generic</serverType>
    <dropExtraFields>true</dropExtraFields>
    <primaryKeyField>AttachPK</primaryKeyField>
    <fields>

    <field>
    <name>timeAttachHappened</name>
    <title>Attach Time</title>
    <type>dateTime</type>
    <useTextField>true</useTextField>
    </field>
    <field>
    <name>attachDate</name>
    <title>Attach Date </title>
    <type>dateTime</type>
    <required>true</required>
    <endDate>new Date()</endDate>
    <pickerIconPrompt></pickerIconPrompt>
    <useTextField>true</useTextField>
    <detail>true</detail>
    </field>
    </fields>

    <serverObject lookupStyle="spring" bean="attachResource"/>
    <operationBindings>
    <binding operationType="fetch" serverMethod="get">
    <serverObject lookupStyle="spring" bean="attachResource"/>
    </binding>
    </operationBindings>
    <operationBindings>
    <binding operationType="add" serverMethod="addAttach">
    <serverObject lookupStyle="spring" bean="attachResource"/>
    </binding>
    </operationBindings>

    </DataSource>


    using this code date picker is coming but not restricting future date.

    #2
    If you want to use a JavaScript expression in the DataSource file, use <JS> tags around it.

    Comment


      #3
      Hi, Thanks for the response.

      I have tried using JS but still not working..Its not showing any warning, simply allowing all date.

      <field>
      <name>attachDate</name>
      <title>Attach Date </title>
      <type>dateTime</type>
      <required>true</required>
      <endDate><JS>new Date()</JS></endDate>
      <pickerIconPrompt></pickerIconPrompt>
      <useTextField>true</useTextField>
      <detail>true</detail>
      </field>

      Comment


        #4
        You can check whether the output is what you intended by using "View Source" to see the JavaScript output of the loadDS tag.

        As far as the restriction: first understand the designed behavior is *not* to restrict the user's choice of date until validation.

        Comment


          #5
          On View Source its showing..

          {
          endDate:new Date(),
          useTextField:"true",
          align:"left",
          detail:true,
          type:"dateTime",
          title:"Attach Date ",
          name:"attachDate",
          required:true
          },

          Its not showing current date for endDate property. Is there any problem in field declaration.

          Second, How it will restrict? until validation? Yes i m calling form.saveData() ..at this time it should get validated? Right?

          Comment


            #6
            The set of available days will only be restricted if the start and end dates fall
            within the same month

            and

            The set of available months will only be restricted if the start and end dates fall within the same year

            This is by design as it allows the user to set the day, month and year in whatever order is convenient, rather than forcing them to pick in a specific order.

            For actual enforcement of a date being in correct range before data is submitted, a Validator of type "dateRange" should always be declared.

            Comment


              #7
              Thankyou for the detail information. I have tried validator also...You just please have a look in my field declation and tell if something is wrong.

              Code:
              (	    <field>
              	    	<name>attachDate</name>
              	    	<title>Attach Date </title>
              	    	<type>date</type>
              	    	<required>true</required>
              	    	<endDate><JS>new Date()</JS></endDate> 
              	    	<useTextField>true</useTextField>
              	    	<align>left</align>
              	    	<detail>true</detail>
              	    	<validators>
              	                <validator type="dateRange"  min="new Date('12/15/1996')" max = "new Date()" />
              			</validators>
              	    </field>

              Comment


                #8
                Specify <min> and <max> in XML Schema date format (yyyy-mm-dd).

                Comment


                  #9
                  <field>
                  <name>attachDate</name>
                  <title>Attach Date </title>
                  <type>date</type>
                  <required>true</required>
                  <min>new Date(''2010-01-01'')</min>
                  <max>new Date('2010-01-08')</max>
                  <useTextField>true</useTextField>
                  <align>left</align>
                  <detail>true</detail>
                  <validators>
                  <validator clientOnly="true" type="dateRange" />
                  </validators>
                  </field>


                  I did , But not working.....You please correct the field declaring where i m missing and doing wroing.

                  Please help me here.

                  Comment


                    #10
                    Amazing number of steps involved here...

                    Move the min and max attributes back where you had them before (where they are documented). Do not use "new Date". Just specify the date only, like min="2010-01-01"

                    Comment


                      #11
                      Thankyou So much...

                      <validator clientOnly="true" type="dateRange" min="2010-01-01" max="2010-01-07"/>

                      Min and max dates are fine..but i want max date should be current date.

                      So how i pass the current date.

                      Comment


                        #12
                        This will work for client-side only enforcement:

                        Code:
                        <validator clientOnly="true" type="dateRange" min="2010-01-01">
                             <max><JS>new Date()</JS></max>
                        </validator>
                        You can declare multiple validators, so you could declare one client- and server-side validator with the "min" only, and a second client-only validator that carries the max. Then you would need to write server code to check that the date is no later than today, and send back a validation error.

                        Comment


                          #13
                          I dont need server side validation..i just want to validate at client side only...But the code you have given is not working...

                          in view source its not rendering max date as current date

                          <validator clientOnly="true" type="dateRange" min="2010-01-01">
                          <max><JS>new Date()</JS></max>
                          </validator>


                          i m using dyanmicForm.validate() explicitly to enforce the validation but not working...Yes when i use hardcoded date it works fine.

                          Comment


                            #14
                            Works here. Show your View Source result.

                            Note you might want to pass an actual String to new Date() (see any JavaScript Reference for acceptable formats), otherwise, it represents the current instant to the millisecond, not a particular day.

                            Comment


                              #15
                              How do i use the validator to restrict the data range?

                              Comment

                              Working...
                              X