Expand my Community achievements bar.

SOLVED

End date should not less than Start date, else CLEAR it

Avatar

Level 8

Hello

I put CONTRACT START DATE and CONTRACT END DATE fields on the form. These 2 objects (Date/Time objjects) i pulled them from Satndard tab of pallette and dropped on my layout page design, fine.

Now, am trying to put a validation that the end dat eshould not lower than start date, so, i got a thread as below from Niall,

http://forums.adobe.com/message/1909551

and i did my FormCalc coding under EXIT event of END DATE field as below,

// Pls. note this FormCalc
// End date should not less than Start date, else CLEAR it - Begin

var stDate
var endDate

stDate = xfa.resolveNode("CUSTOMER.Page31_Contracts.Con_Whole_Page.CON_Basic_Info.CON_START_DATE").rawValue
endDate = xfa.resolveNode("CUSTOMER.Page31_Contracts.Con_Whole_Page.CON_Basic_Info.CON_END_DATE").rawValue

if (stDate > endDate) then
    xfa.host.messageBox("End date is lower than Start date! End date is cleared")
    xfa.resolveNode("CUSTOMER.Page31_Contracts.Con_Whole_Page.CON_Basic_Info.CON_END_DATE").rawValue = null
endif

// End date should not less than Start date, else CLEAR it - End

I tried in VALIDATE, CALCULATE, CHANGE events of END DATE, but nothing working!!

PLs. let me kow how can i achieve my requirement? I am anewbie,

Thank you

1 Accepted Solution

Avatar

Correct answer by
Level 5

If you use the exit event, you will probably have to have the same code on both the start and end date fields since they have a dependancy on each other. Maybe better to try the validate event of the end date so that if either field is changed the event gets fired. You can try the following for validate event

// Pls. note this FormCalc

// End date should not less than Start date, else CLEAR it - Begin

var stDate

var endDate

stDate = CON_START_DATE.rawValue

endDate = $.rawValue

if ( HasValue(endDate) ) then

    if (stDate > endDate) then

        xfa.host.messageBox("End date is lower than Start date! End date is cleared")

        $.rawValue = null

    endif

endif

1

// End date should not less than Start date, else CLEAR it - End

View solution in original post

9 Replies

Avatar

Correct answer by
Level 5

If you use the exit event, you will probably have to have the same code on both the start and end date fields since they have a dependancy on each other. Maybe better to try the validate event of the end date so that if either field is changed the event gets fired. You can try the following for validate event

// Pls. note this FormCalc

// End date should not less than Start date, else CLEAR it - Begin

var stDate

var endDate

stDate = CON_START_DATE.rawValue

endDate = $.rawValue

if ( HasValue(endDate) ) then

    if (stDate > endDate) then

        xfa.host.messageBox("End date is lower than Start date! End date is cleared")

        $.rawValue = null

    endif

endif

1

// End date should not less than Start date, else CLEAR it - End

Avatar

Level 8

Thank you, perfect.

By chance if you hv time, pls. let me know for the other relevent validation, as below,

The start date should not be lower than current date/todays date/today? I have opened a new thread for it, the link is as below

http://forums.adobe.com/thread/974950    

Thank you

Avatar

Level 8

Hello

I have implemented your (dohanlon's) solution, it worked fine for 2 days, all of suddden i am getting the below error message as soon as the form is launching on the browser (prior to displaying any layout objects, the time glass is runing/blue round symbol going on..., i am getting the error message), its as below

"CON_END_DATE validation failed!"

I tried the form by saving on my local laptop and tried to reopen, same this is happening!

Pls. let me know do i need to put any PATTERN or some more Script or i need to change the event from VALIDATION to some other?

Thank you

Avatar

Level 5

Are you sure you still have the 1 at the end of the script block? That tells the validation engine not to fail and display a default message. Also check the patterns are the same for both date fields

Avatar

Level 8

Hello,

Ohhhhhhhhhhhhhhhhhhhhhhh........ yup, i thought "1" is typed by mistake by

me!!! henec deleted

Hmmmmmm..... JavaScript/FormCalc (I work on 4th generation language, hence

we dont hv these kind of stuff)

Thank you

Avatar

Level 8

Also, i wan to let you know that i did not put any kind of PATTERNS on the field/object. I have selected DEFAULT LOCAL, bcz my form is global, i mean, its for US and Europe

Pls. let me know do i need to put any PATTERNS (edit, validate) to support your solution/code?

Thank you    

Avatar

Level 5

Should be fine without setting a pattern for this