Laravel-Backpack / CRUD

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

`crud.field()` js library bugs #4329

Closed tabacitu closed 2 years ago

tabacitu commented 2 years ago

@pxpm said (Originally posted by @pxpm in https://github.com/Laravel-Backpack/CRUD/pull/4312#pullrequestreview-944434626)


Hey @tabacitu amazing work here! So I am just giving this a round up review, I am not going to work on fixes unless you tell me to.

So until now I figured out that: 1) It does not work with arrayed name fields like date_range. It will throw an error in wrapper because of the bp-field-name

Yeah, we SHOULD fix this.

2) jquery date_picker and datetime_picker catch the change event when initializing, but then don't catch the change when you select a date from the picker. (also happens with: address_algolia fields)

Yeah, we MUST fix this.

3) In the date html field, if you are manually typing the date, the change event is triggered in every keystoke when you start inputing the year. Same happens with datetime, time, month, week

I'm ok with this... I don't think we should do anything about this, it's just the way these work. Wouldn't you agree? I'd say WON'T DO.

crud.field('date').onChange(function(e, value) {
    console.log('date')
    var now = new Date();
    var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
    var selectedDate = Date.parse(value);
    if (selectedDate < today) {
        new Noty({
            type: "error",
            text: "date cant be lower than today"
          }).show();
    }
});

4) for hasOne with dot notation the bp-field-name should probably be address.street so developer can target it with address.street, otherwise it needs to know beforehand that we will change the name to address[street]. At the moment trying to add address.street as a field name in javascript will break the jquery search, changing to passing full strings to the search query makes it work:

Thanks, we COULD fix this.

constructor(fieldName) {
            this.name = fieldName;
            this.wrapper = $('[bp-field-name="'+ this.name +'"]');
            this.input = $('[bp-field-main-input][name="'+ this.name +'"]');
            // if no bp-field-main-input has been declared in the field itself,
            // assume it's the first input in that wrapper, whatever it is
            if (this.input.length == 0) {
                this.input = $('[bp-field-name="'+ this.name +'"] input, [bp-field-name="'+ this.name +'"] textarea, [bp-field-name="'+ this.name +'"] select').first();
            }
            this.value = this.input.val();
        }

5) The multiple selects use an hidden input with empty value, not to store the field itself but to submit when nothing is selected. I could not target the selects with name or name[]. I tried to add:

'wrapper' => [
   'class' => 'form-group col-md-6',
   'bp-field-main-input' => 'name[]'
],

No avail here.

Great catch! We MUST fix this.

6) can't make any js editor work with onChange, neither by typing or moving focus out.

Another great catch, we MUST fix this.

7) video field does not catch the event too.

SHOULD DO.

8) color_picker jquery plugin will trigger the change event when you drag to chose the color triggering hundreds of times in a short period.

🤷‍♂️ I'm ok with it... to be honest... I'd say WON'T DO.

9) icon_picker does not work too

SHOULD DO

10) I haven't tried this with repeatable, but we should consider the "events/hooks" aproach for table as this script has no effect on table field.

COULD DO

tabacitu commented 2 years ago

@pxpm heads-up, I've moved the bugs you found here. To fix that branch let's use:

tabacitu commented 2 years ago

@pxpm let's centralize our testing in this table, using this demo branch. Legend:

Field onChange() hide() show() enable() disable() require() unrequire() Custom
checkbox check(), ✅ uncheck()
checklist -
checklist_dependency -
color -
custom_html ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️
date -
datetime -
email -
enum -
hidden -
month -
number -
password -
radio -
range -
select (1-n relationship) -
select_grouped -
select_multiple (n-n relationship) -
select_from_array -
summernote -
text -
textarea -
time -
upload -
upload_multiple -
url -
view ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️
week -
address_algolia PRO -
address_google PRO -
browse PRO -
browse_multiple PRO -
base64_image PRO -
ckeditor PRO -
color_picker PRO -
date_range PRO -
date_picker PRO -
datetime_picker PRO -
easymde PRO -
icon_picker PRO -
image PRO -
relationship PRO -
repeatable PRO -
select2 (1-n relationship) PRO -
select2_multiple (n-n relationship) PRO -
select2_nested PRO -
select2_grouped PRO -
select_and_order PRO -
select2_from_array PRO -
select2_from_ajax PRO -
select2_from_ajax_multiple PRO -
table PRO -
tinymce PRO -
video PRO -
wysiwyg PRO ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️ ⛔️
pxpm commented 2 years ago

@tabacitu I've added some PR's that cover alot of scenarios but I didn't update the table, I think it's better that when you test the PR's and they work you do the table update as a "I confirmed it works".

Cheers

tabacitu commented 2 years ago

@tabacitu I've added some PR's that cover alot of scenarios but I didn't update the table, I think it's better that when you test the PR's and they work you do the table update as a "I confirmed it works".

Exactly. That's what I've been doing 😉 Great minds think alike 😅🙏

tabacitu commented 2 years ago

TODO:

pxpm commented 2 years ago

@tabacitu from my last tests (with pending pr's merged) it's only missing:

tabacitu commented 2 years ago

IMPORTANT - single-source-of-truth branches we're using:

From now on

Let's do this!!! 💪🎉

tabacitu commented 2 years ago

I'm SUPER-happy to announce that I've just tested this the 3rd time and I'm happy with it, I think it's FINAL:

movie-images-drive-13ZVRnWnmSMaRy