[javascript] fix AJAX user preference validation stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Thu, 28 May 2009 19:07:06 +0200
branchstable
changeset 1992 b073057c2756
parent 1981 e6eed4324357
child 1993 b3b51389566b
child 2007 62d72d65e50d
[javascript] fix AJAX user preference validation - use $elt.val() instead of $elt.attr('value') - fix radio button handling
web/data/cubicweb.preferences.js
--- a/web/data/cubicweb.preferences.js	Thu May 28 11:41:36 2009 +0200
+++ b/web/data/cubicweb.preferences.js	Thu May 28 19:07:06 2009 +0200
@@ -84,10 +84,8 @@
     jQuery(form).find('[type=text]').each(function () {
 	    unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
 	});
-    jQuery(form).find('input[type=radio]').each(function () {
-	    if (jQuery(this).attr('checked')){
-		unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
-	    }
+    jQuery(form).find('input[type=radio]:checked').each(function () {
+            unfreezeButtons = _checkValue(jQuery(this), unfreezeButtons);
      });
 
     if (unfreezeButtons){
@@ -103,7 +101,7 @@
 
 function _checkValue(input, unfreezeButtons){
      var currentValueInput = jQuery("input[name=current-" + input.attr('name') + "]");
-     if (currentValueInput.attr('value') != input.attr('value')){
+     if (currentValueInput.val() != input.val()){
 	 input.addClass('changed');
 	 unfreezeButtons = true;
      }else{
@@ -121,12 +119,15 @@
 	    var name = currentValueInput.attr('name').split('-')[1];
 	    jQuery(form).find("[name=" + name + "]").each(function (){
 		    var input = jQuery(this);
-		    if(input.attr('type')=='radio'){
-			if(input.attr('checked')){
-			    currentValueInput.attr('value', input.attr('value'));
+		    if(input.attr('type') == 'radio'){
+			// NOTE: there seems to be a bug with jQuery(input).attr('checked')
+			//       in our case, we can't rely on its value, we use
+			//       the DOM API instead.
+			if(input[0].checked){
+			    currentValueInput.val(input.val());
 			}
 		    }else{
-			currentValueInput.attr('value', input.attr('value'));
+			currentValueInput.val(input.val());
 		    }
 		});
     });