formapro / JsFormValidatorBundle

The Javascript validation for Symfony 2, 3 and 4 forms
MIT License
128 stars 56 forks source link

Multiple Forms for one Model #136

Open bastos71 opened 6 years ago

bastos71 commented 6 years ago

I think i'm facing a huge error of conception here :/

My problem is that I have one Form Type, but it is rendered multiple times into a single page (in a listing view, inside a table for some reasons)

It seems that the entire Javascript Plugin of JsFormValidatorBundle is built for the logic 1 Model = 1 Form, so when I render a form at least twice (for 2 differents entities for example), the plugin only initializes the first one. And this seems logic because in the source code, forms are retrieved by Form BlockPrefixes

this.addModel = function (model, onLoad) {
    var self = this;
    if (!model) return;
    if (onLoad !== false) {
        this.onDocumentReady(function () {
            self.forms[model.id] = self.initModel(model);
        });
    } else {
        self.forms[model.id] = self.initModel(model);
    }
};

Anyone's having the same problem ? :/