Skip to content
Discussion options

You must be logged in to vote

Hi @rchampagneca!

Indeed some fields are not linear in terms of setting a value. Specially jQuery fields.
In most of the fields field.value = 'new value' will easily set a new value, this date picker requires extra steps.

Your solution works 👌


By the way, just for the reference, CRUD Fields can make it easy to manage the inputs.

function setDateForInputField(fieldName, monthsToAdd) {
	let field = crud.field(fieldName);
	let $datepicker = field.wrapper.find('[data-bs-datepicker]').datepicker();
	
	// date manipulation
	let date = new Date();
	date.setMonth(date.getMonth() + monthsToAdd)
	
	$datepicker.datepicker('setDate', date);
	field.value = date.toISOString().slice(0, 10);
}

It's not …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@rchampagneca
Comment options

Answer selected by promatik
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants