asp.net mvc 4 - jquery dialog validations works only once when i run the code , second time it won't print the error messages -
when first run code in mvc4, validates fields of jquery dialog box, not printing errors second time....can please me? have jqueryvalidate.min.js , jquery.validate.unobtrusive.min.js html code:
<div id="add_task_dialog_box" class="hide"> @using (html.beginform("saveevent", "base", formmethod.post, new { id = "form_data", @class = "form-horizontal", style = "display: none;" })) { @html.validationsummary(true) @html.antiforgerytoken() @*<form id="form_data" class="form-horizontal" style="display: none;">*@ <fieldset class="form-group"> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right " style="font-weight:bold;font-size:13px;text-align:left;font-family:arial unicode ms;">project name</label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.dropdownlistfor(model => model.task_runsmodel.project_id, db.getprojects(a), "--select--", new { style = "width:200px;", id = "myproject"}) </div> </div> </div> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right error"> </label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.validationmessagefor(model => model.task_runsmodel.project_id, string.empty, new { @class = "id_form_valid error error" }) </div> </div> </div> <br /><br /> <div class="space-6"></div> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right " style="font-weight:bold;font-size:13px;text-align:left;font-family:arial unicode ms;">select task</label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.dropdownlistfor(model => model.task_runsmodel.task_id, db.gettasks(a, c), "--select--", new { style = "width:200px;", id = "mytask"}) </div> </div> </div> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right "></label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.validationmessagefor(model => model.task_runsmodel.task_id, string.empty, new { @class = "id_form_valid error" }) </div> </div> </div> <br /><br /> <div class="space-6"></div> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right " style="font-weight:bold;font-size:13px;text-align:left;font-family:arial unicode ms;">status</label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.dropdownlistfor(model => model.task_runsmodel.status, db.getstatus(), "---select---", new { style = "width:200px", id = "taskstatus" }) </div> </div> </div> <div> <label class="control-label col-xs-12 col-sm-3 no-padding-right "></label> <div class="col-xs-12 col-sm-9"> <div class="clearfix"> @html.validationmessagefor(model => model.task_runsmodel.status, string.empty, new { @class = "id_form_valid error" }) </div> </div> </div> <div class="col-lg-12 col-md-3 col-sm-3 col-xs-12"> <div id="chatarea" class="dropdown-toggle" style="float: left; padding-left: 20px; overflow-y: auto; overflow-x: auto;"> </div> <b style="float: right; padding-right: 20px;" class="glyphicon glyphicon-chevron-down" id="displaycomment"></b> </div> <div id="textareadiv" style="padding-top:3px;"> <span class="col-lg-3 col-md-3 col-sm-9 col-xs-12" style="padding-left: 12px; width: inherit;">@html.textareafor(model => model.task_runsmodel.comment1, new { id = "comment", ariahidden = "true", placeholder = "write comment", @class = "form-control wp-editor-area", cols = "65", rows = "3", style = " width: calc(100%);" }) </span> </div> @* <div id="commentdiv" class="dropdown-toggle" style=" padding-left: 20px; overflow-y: auto; overflow-x: auto;width:100%"> <ul id="current_comments" type="none" style="font-weight:bold;"> </ul> </div>*@ @*<div id="textareadiv" style="padding-top:3px;"> <span class="col-lg-3 col-md-3 col-sm-9 col-xs-12" style="padding-left: 12px; width: inherit;">@html.textareafor(model => model.task_runsmodel.comment1, new { id = "comment", ariahidden = "true", placeholder = "write comment", @class = "form-control wp-editor-area", cols = "65", rows = "3", style = " width: calc(100%);" }) </span> *@ @*<button id="textareabutton" type="button" class="btn btn-success btn-xs" style="float:right; border-radius:8px;"> send </button> *@ @* </div>*@ </fieldset> }
jquery :
$("#form_data").dialog({ open: function(event, ui){ $('#form_data').css('overflow','hidden'); row={ } c=row.project_name; var ddlstates = $("#mytask"); var items = '<option>--select--</option>'; var data = c, params = {'project_id':""}; $.ajax({ type: 'get', url: '@url.action("gettasks", "base")', data:params, success: function (data) { // alert(data.task_name); debugger; ddlstates.html(''); $.each(data, function (id, option) { //ddlstates.append($('<option></option>').val(option.id).html(option.name)); items += "<option value='" + option.value + "'>" + option.text + "</option>"; }); $('#mytask').html(items); } }); // $('.ui-dialog-content').css('width','100%'); }, close: function(event,ui) { debugger; // $("#form_data").validate().resetform(); // document.getelementbyid("comment").value = ""; if ($('#displaycomment').hasclass("glyphicon glyphicon-chevron-down")) { t=1; } else { $('#chatarea').slidetoggle('500'); $('#displaycomment').removeclass("glyphicon glyphicon-chevron-up").addclass("glyphicon glyphicon-chevron-down"); } $(".error").hide(); }, autoopen: true, width:'38%', title: "<div class='widget-header widget-header-small' id='div1'><h3 class='smaller'>add event </h3></div>", title_html: true, resizable: false, minheight: 200, maxheight: '90%', height: 'auto', modal: true, // fluid: true, //new option draggable:false, overflow:'auto', position:{my:"center" , at:"center", of:window}, buttons: [ { text: "cancel", "class": "btn btn-primary btn-minier", click: function () { $(this).dialog("close"); } }, { text: "submit", "class": "btn btn-primary btn-minier", click: function () { debugger; if($("#form_data").valid()) { debugger; var project_id=$('#myproject').val(), task_id=$('#mytask').val(), startdate = st.format('yyyy-mm-dd hh:mm:ss'), enddate=ed.format('yyyy-mm-dd hh:mm:ss'), status = $('#taskstatus :selected').text(), comment1= $('#comment').val(), params = {'project_id':project_id,'task_id':task_id,'start_time':startdate,'end_time':enddate,'status':status,'comment1':comment1}; $.ajax({ type: 'post', url: '@url.action("saveevent", "base")', data: params, //contenttype: "application/json; charset=utf-8", //datatype: "json", success: function (response) { $('#calendar').fullcalendar( 'refetchevents' ); $('#calendar').fullcalendar( 'rerenderevents' ); $('#form_data').dialog("close"); } //to reset form }); var frm=document.getelementbyid('form_data'); frm.reset(); } } } ] });
Comments
Post a Comment