jquery - s:checkbox fieldValue always true in validation before submitting -


i using struts 2 <s:checkbox /> in form processing, along angularjs , jquery.
before submitting, need validation , until in project:

when press submit button, function called:

$scope.processform('myform', '<s:url value="/form/validate.action" />',                               '<s:url value="/form/save.action" />'); 

, processform(formid, validateurl, submiturl) function defined us:

$scope.processform = function(form, validateurl, submiturl) {     window.scroll(0,0);     proccessformservice.processstandarform(form, validateurl, submiturl); }; 

and furthermore, have processstandarform() defined in global service:

angular.module('ourapp').controller('myformctrl',                                      function($scope, $modal, proccessformservice) { ... } 

in service:

(function() {        angular.module('ourapp').factory('proccessformservice', ['$http', function($http) {      processstandarform: function(form, validateurl, submiturl) {                 this.processform(form, validateurl, submiturl);     },      processform: function(form, validateurl, submiturl, success) {          if ((typeof form) == 'string') {             form = document.getelementbyid(form);         }          var data = this.form2object(form);         var ctrl = this;          if (data) {             if (validateurl) {                 $http({                     method  : 'post',                     url     : validateurl,                     data    : $.param(data),  // pass in data strings                     headers : { 'content-type': 'application/x-www-form-urlencoded' }            // set headers angular passing info form data (not request payload)                 }).success(function() {                     if (!success) {                         form.action = submiturl;                         form.submit();                     } else {                         ctrl.submitajaxform(submiturl, data, success)                     }                 });             } else if (submiturl) {                 if (!success) {                     form.action = submiturl;                     form.submit();                 } else {                     this.submitajaxform(submiturl, data, success)                 }             }         }            }, } 

basically, submitting twice form, firstly validation, submitting.

what don't understand, if debug in action class, in function of validate(), boolean value of <s:checkbox /> true, in submit() function, boolean values submitted correctly, according checked/not checked. checkboxs this:

<div class="col-sm-12 form-checkbox">      <s:checkbox name = "myform.married"               ng-model = "checkboxmodel"                  value = "<s:property value='%{myform.married}'/>"             ng-change = "submitcheckbox();"                ng-init = "checkboxmodel= %{myform.married}"                  theme = "simple"             ng-disabled = "anotherfunction()" /> </div> 

i understand that, value submitted fieldvalue="xxx" in <s:checkbox />, , default true. did change fieldvalue of every checkbox before page loaded. although script executed, nothing changed. still true in validation.

$(document).ready(function(){     $( "input:checkbox" ).each(function(){         var checkbox = $(this);         var checked = checkbox.prop("checked");//sera false/true         if (checked == true){             checkbox.prop("fieldvalue", "true");         } else {             checkbox.prop("fieldvalue", "false");         }     }); }); 

so, how can right boolean values not in submitting, in validation?? angular service wrongly written ? doubt not able figure out question.

suspected data not serialized used angular $http().

if want emulate $.param() used in jquery should use built-in serializer $httpparamserializerjqlike.

alternative $http params serializer follows jquery's param() method logic. serializer sort params alphabetically.

to use serializing $http request parameters, set paramserializer property:

$http({   url: myurl,   method: 'get',   params: myparams,   paramserializer: '$httpparamserializerjqlike' }); 

it possible set default paramserializer in $httpprovider.

additionally, can inject serializer , use explicitly, example serialize form data submission:

.controller(function($http, $httpparamserializerjqlike) {   //...    $http({     url: myurl,     method: 'post',     data: $httpparamserializerjqlike(mydata),     headers: {       'content-type': 'application/x-www-form-urlencoded'     }   });  }); 

another ways convert $.param angular can find in convert $.param in angularjs


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -