Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Datepicker Month Topic is solved
-
- Posts: 154
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 2 times
- Been thanked: 1 time
Datepicker Month
I'd like to have a datepicker with format 'M yyyy' but can't work out how to set the options for the datepicker.
Ideally, the field value would be the first day of the chosen month but that's not essential.
Ideally, the field value would be the first day of the chosen month but that's not essential.
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: Datepicker Month
The nuDate form format 'mm yyyyy' (all lowercase) allows you to select both month and year.
Note that the month will appear as a two-digit number—e.g., 01, 02, 12, etc.
Note that the month will appear as a two-digit number—e.g., 01, 02, 12, etc.
-
- Posts: 154
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 2 times
- Been thanked: 1 time
Re: Datepicker Month
But the datepicker still shows days and I would like to have startView and pickLevel as "1 - months" (as shown on datepicker demo).
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
-
- Posts: 154
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 2 times
- Been thanked: 1 time
Re: Datepicker Month
Like this:
You do not have the required permissions to view the files attached to this post.
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: Datepicker Month
This specific format may not be supported at the moment (to be verified)
The Vanilla JS datepicker format will need to be inspected and translated into a format compatible with nuBuilder.
Another solution: Consider using the Input Type "Month", an HTML5 <input type="month"> element, which allows selection of both year and month.
The Vanilla JS datepicker format will need to be inspected and translated into a format compatible with nuBuilder.
Another solution: Consider using the Input Type "Month", an HTML5 <input type="month"> element, which allows selection of both year and month.
-
- Posts: 154
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 2 times
- Been thanked: 1 time
Re: Datepicker Month
The field does contain a valid date value after selection of the month so perhaps it will be possible to accomodate datepicker options
I would use the HTML5 input type (it was my first thought), but we currently use Firefox. Perhaps I'll have to give in and change to Chromium...
I would use the HTML5 input type (it was my first thought), but we currently use Firefox. Perhaps I'll have to give in and change to Chromium...
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: Datepicker Month
If you declare a function called nuOnSetCalendarOptions in your form's Custom Code, you can override the default Vanilla JS Datepicker options.
For example:
You can also modify options conditionally for a specific calendar input by checking the object id
This lets you apply different settings to different fields within the same form.
For example:
Code: Select all
window.nuOnSetCalendarOptions = function(id, { options }) {
return Object.assign(options, {
startView: 1, // "months" view
pickLevel: 1 // select only month/year
});
};
Code: Select all
window.nuOnSetCalendarOptions = function(id, { options }) {
// Replace 'yourSpecificId' with the id you want to target
if (id === 'yourSpecificId') {
return Object.assign({}, options, {
startView: 1, // "months" view
pickLevel: 1 // select only month/year
});
}
// If id doesn't match, return options unchanged
return options;
};
You do not have the required permissions to view the files attached to this post.
-
- Posts: 154
- Joined: Mon Dec 05, 2011 12:23 pm
- Location: Newton Abbot, UK
- Has thanked: 2 times
- Been thanked: 1 time
Re: Datepicker Month
That works for me, though one small difference from the online demo is the date value that gets passed down to my PHP procedure shows the current day of month rather than the first day (as shown in the demo), but I can work around that for the time being.
*UPDATE* : with input format "yyyy-mm-dd" I get the first day of month, with my chosen custom format of "mmmm yyyy" I get today's date.
*UPDATE* : with input format "yyyy-mm-dd" I get the first day of month, with my chosen custom format of "mmmm yyyy" I get today's date.
-
- nuBuilder Team
- Posts: 4416
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 74 times
- Been thanked: 472 times
- Contact:
Re: Datepicker Month
You can use
Another option is to use
(*) This has just been added to Github
nuSetNuDataValue()
within the form's Before Save (BS) event to modify field values before they are saved to the database. For example, in your case, you could replace the day portion of a date with "01":Code: Select all
$nuMainForm = nuHash()['nuFORMdata'][0]->id;
$idValue = nuGetNuDataValue($nudata, $nuMainForm, 'mydateobjectid'); // <------------------- replace with your Object ID
function replaceDayWithFirst($dateString) {
// Validate format: YYYY-MM-DD using regex
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateString)) {
// Replace the day part with 01
return substr($dateString, 0, 8) . '01';
} else {
// Return original value
return $dateString;
}
}
$newValue = replaceDayWithFirst($idValue);
nuSetNuDataValue($nudata, $nuMainForm, 'mydateobjectid', $newValue); // <------------------- replace with your Object ID
Another option is to use
nuOnRawValueFormatted()
* in the form's Custom Code to replace the day portion of the date with "01".(*) This has just been added to Github
Code: Select all
function nuOnRawValueFormatted(id, value, format) {
if (id === 'mydateobjectid') { // <------------------- replace with your Object ID
if (value.length === 10) {
return value.slice(0, -2) + "01";
}
}
}