meteor-autoform-select2 icon indicating copy to clipboard operation
meteor-autoform-select2 copied to clipboard

Clear all selected when submit error, but not clear when submit success???

Open thearabbit opened this issue 9 years ago • 7 comments

I have the problem when I submit form error, it clear all of selected value. But when the submit form success, it not clear selected label (value is empty).

thearabbit avatar Jun 06 '15 08:06 thearabbit

yep, I also have this issue. @thearabbit did you ever get around this?

KristerV avatar Jun 25 '15 13:06 KristerV

Oh, How the solution?

thearabbit avatar Jun 26 '15 01:06 thearabbit

I got around by using selectize. Thought it has exactly the same issue, but at least I could reset it "manually".

AutoForm.addHooks(['insertProductForm'], {
    onSuccess: function(formType, result) {
        $('select')[0].selectize.clear()
    }
})

Select2 also should have this functionality, but I just couldn't get $.fn.select2.defaults.reset() to work.

KristerV avatar Jun 26 '15 07:06 KristerV

I tried selectize, but have any problem withe onchage order. for example I have 2 selectize and when I on change the first to change value of the second, it not work on the second.

thearabbit avatar Jun 26 '15 12:06 thearabbit

This worked for me, although it clears all selects.

AutoForm.addHooks(['insertProductForm'], {
    onSuccess: function(formType, result) {
        $('select').each(function() { //Select2 doesnt clear on its own
          $(this).select2('val', '');
        });
    }
})

drew-y avatar Jul 17 '15 21:07 drew-y

Look great, it work fine on success hook. But I still have problem with onError (all select2 is clear).

thearabbit avatar Jul 18 '15 01:07 thearabbit

I Haven't had a chance to test the onError case yet.

drew-y avatar Jul 18 '15 04:07 drew-y