;(function (define) { 'use strict'; define([ 'jquery', 'underscore', 'backbone', 'common/js/utils/edx.utils.validate' ], function($, _, Backbone, EdxUtilsValidate) { return Backbone.View.extend({ tagName: 'form', el: '', tpl: '', fieldTpl: '#form_field-tpl', events: {}, errors: [], formType: '', $form: {}, fields: [], // String to append to required label fields requiredStr: '*', submitButton: '', initialize: function( data ) { this.model = data.model; this.preRender( data ); this.tpl = $(this.tpl).html(); this.fieldTpl = $(this.fieldTpl).html(); this.buildForm( data.fields ); this.listenTo( this.model, 'error', this.saveError ); }, /* Allows extended views to add custom * init steps without needing to repeat * default init steps */ preRender: function( data ) { /* Custom code goes here */ return data; }, render: function( html ) { var fields = html || ''; $(this.el).html( _.template( this.tpl, { fields: fields })); this.postRender(); return this; }, postRender: function() { var $container = $(this.el); this.$form = $container.find('form'); this.$errors = $container.find('.submission-error'); this.$submitButton = $container.find(this.submitButton); }, buildForm: function( data ) { var html = [], i, len = data.length, fieldTpl = this.fieldTpl; this.fields = data; for ( i=0; i' + error.responseText + '']; this.setErrors(); this.toggleDisableButton(false); }, setErrors: function() { var $msg = this.$errors.find('.message-copy'), html = [], errors = this.errors, i, len = errors.length; for ( i=0; i