alexander-schranz/sulu-form-bundle

Add js validation example

Closed this issue · 1 comments

Add js validation example

Based on the Dropzone Example, I would handle it the following way and replace this.$el.submit(this.submit.bind(this)); with this.initializeValidation();, which looks something like:

initializeValidation: function() {
    this.$el.validate({
        submitHandler: function(form) {
            // Disable button.
            this.$el.find('[type=submit]').prop('disabled', true);

            // Submit form.
            if (!this.hasFiles()) {
                form.submit();
                return true;
            }

            // If there are some files, submit the form via dropzone.
                this.submitViaDropzone();
            }.bind(this)
    });
},

submitViaDropzone: function() {
    for (var i = 0, length = this.dropzones.length; i < length; i++) {
        if (this.dropzones[i].getQueuedFiles().length) {
            this.dropzones[i].processQueue();
            return true;
        }
    }

    return false;
}