Enter a date value using javascript in CakePHP

I want to get the date value in javascript and I use the default date function cakephp. The problem is that in each drop-down list there is 3 (day-month-year) scatter and .change replacement, but I want to get the full date (e.g., 20-11-2012). I want to get the date value before sending, because I want to apply validations to it.

I think I forgot to mention that I do not want to use the "date picker". enter image description here

+4
source share
1 answer

You must use cake naming conventions for form elements.

For example, if you call $this->input('Model.field', array('type'=>'date')) in the view, the generated html-selectboxes have the following identifiers: #ModelFieldMonth, #ModelFieldDay, #ModelFieldYear .

So, the code to get the full date in JS:

 var date = $('#ModelFieldYear').val() + '-' + $('#ModelFieldMonth').val() + '-' + $('#ModelFieldDay').val(); 
+1
source

Source: https://habr.com/ru/post/1439120/


All Articles