doubletake
Posts: 0
Joined: Sat May 25, 2013 5:55 pm

date picker value via JS

How do I reference the value of the datepicker in JS by using the name of the datepicker component?

The dates are required fields in my validation. I have multiple dates in the same page (e.g. startDate, endDate, etc.), so it cannot be based on a generic selector.

Thanks,
Don

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

date picker value via JS

Hi,

I'll take a look.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

date picker value via JS

Try the following code:
codeAppery("mobiledatepicker_2").getAttr("defaultDateValue")/code

doubletake
Posts: 0
Joined: Sat May 25, 2013 5:55 pm

date picker value via JS

Sorry. I didn't asked the right question. My bad :(

Jquery.Validity uses the component id/name selector to check required

$('#myinput').require('this field is required');
$("[name='myinput']").require('this field is required');

this works fine in Appery.io.

in the case of the date picker, it looks like it uses a text input component to store the selected date. It looks like this input doesn't have an name or an id to use. i.e. it doesn't use the name of the mobiledatepicker.

I'm sure I can write something custom for dates using the getAttr, like you suggest here. However, I was hoping not to have to. Lazy :(

Any ideas?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

date picker value via JS

Appery.io applications are little different from usual web pages.
It's all about the need to automatically generate these web pages. It has a certain effect on the page components use case. The standard Datepicker was modified for the Builder.

doubletake
Posts: 0
Joined: Sat May 25, 2013 5:55 pm

date picker value via JS

I got it working by setting the id property of the input child of the datePicker, then using that id for the validation.

I do this in my page load setupValidation() function:

$("[name='startDate']").find('input').attr('id','inputStartDate');

then on submit of of the form, this now works to validate.
$("#inputStartDate").require('required');

Never give up :)

Ole Henrik Oftedal
Posts: 0
Joined: Thu Apr 19, 2012 4:52 pm

date picker value via JS

Hi Don!

Thank you so much for not giving up. I have struggled with this over time and my solution worked, but your solution is much much better!

Now it is easy to both set the date and get the selected date from the component.

best regards

Ole H. Oftedal
Timeflex Systemer AS
http://www.timeflex.com
http://www.timeflex.no

Return to “Issues”