Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 885 forks source link

CrudField JavaScript Library - not able to set value on all field types #5009

Open pxpm opened 1 year ago

pxpm commented 1 year ago

Discussed in https://github.com/Laravel-Backpack/community-forum/discussions/436

Originally posted by **rchampagneca** March 15, 2023 Tried to use the **CrudField JavaScript Library** calls to get and set dates for a **Bootstrap Date Picker** (Backpack pro). Is it supported ? Tried this script as a workaround : ```js function setDateForInputField(variableName, monthsToAdd) { var element = document.querySelector(`[bp-field-name="${variableName}"]`); var formattedtoValue = null; if (monthsToAdd !== null) { var currentDate = new Date(); var toValue = new Date(currentDate.setMonth(currentDate.getMonth() + monthsToAdd)); var formattedtoValue = toValue.toISOString().slice(0, 10); } var inputField = element.querySelector('input[bp-field-main-input]'); var dateField = element.querySelector('input[data-bs-datepicker]'); $(dateField).datepicker('setDate', toValue); // Order of the next 2 methods seems important ! $(inputField).attr("value", formattedtoValue); } ``` Does the job.
tabacitu commented 1 year ago

I totally agree we should do this at some point... but it's A LOT of work to do this for all field types... so let's postpone this. Until then, developers who need to do this can find individual solutions for their use cases.

tabacitu commented 1 year ago

Good find! 👍