$(function() { $("#nature").select2(); $('select#nature').on("select2:select", function(e) { $('.nature').addClass('nature_selected'); }); $('label.nature').on('click', function (e) { $('#nature').select2('open'); }); //on input after error $('input').on('keypress', function(e){ $(e.target).closest('.form-label-group').removeClass('has-error').find("span.help-block").text(''); }); //remove validation errors on select for subject $('select.s1').on('change', function(e) { if ($(e.target).val().length > 0) { if ($(e.target).prop("name")) { $(".select2-container--default .select2-selection--single").css({ "border-color": "#ccc" }) $(e.target).closest('.form-label-group').removeClass('has-error').find("span.help-block").text('') } } }); //autofocus the first field $("#fname").focus(); $('#send_msg_btn').on('click', function(){ var options = { "submitWhenValid" : function(){ var dialog; $.ajax({ url : app.get_vars().baseurl+"send_comment", type : "POST", data : $("form#contact_information").serialize(), beforeSend : function(){ dialog = bootbox.dialog({ message: '
'+app.get_vars()._app.notif.loading+'
', closeButton: false }); }, success : function(result) { dialog.modal("hide"); app._notify(result.mtype, result.message); if(result.mtype == 'success'){ window.setTimeout(function(){window.location.href = app.get_vars().baseurl},3000); } } }); }, "validation" : { "form_id": "form#contact_information", "displayClass" : "pull-right", "rules": { "name": { "required": true }, "fname": { "required": true }, "sender": { "required": true, "email" : true }, "nature": { "required": true } ,"comment": { "required": true } } } }; app._form._validateContactForm(options); }); // From event info box contact button $('#send_msg_btn_nous').on('click', function(){ var options = { "submitWhenValid" : function(){ var dialog; $.ajax({ url : baseurl+"send_comment_nous", type : "POST", data : $("form#contact_information").serialize(), beforeSend : function(){ dialog = bootbox.dialog({ message: ''+app.get_vars()._app.notif.loading+'
', closeButton: false }); }, success : function(result) { dialog.modal("hide"); app._notify(result.mtype, result.message); if(result.mtype == 'success'){ window.setTimeout(function(){window.location.href = app.get_vars().baseurl},3000); } } }); }, "validation" : { "form_id": "form#contact_information", "displayClass" : "pull-right", "rules": { "name": { "required": true }, "fname": { "required": true }, "sender": { "required": true, "email" : true }, "nature": { "required": true } ,"comment": { "required": true } } } }; app._form._validateContactForm(options); }); });