Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pxpm opened this issue Mar 31, 2023 · 2 comments
Open

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

pxpm opened this issue Mar 31, 2023 · 2 comments

Comments

@pxpm
Copy link
Contributor

pxpm commented Mar 31, 2023

Discussed in Laravel-Backpack/community-forum#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 :

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
Copy link
Member

tabacitu commented Apr 3, 2023

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
Copy link
Member

tabacitu commented Apr 3, 2023

Good find! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants