fix error key / field input detection (field's name include -role when specified, the error key *may* include it
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 14 Jan 2010 11:12:52 +0100
changeset 4239 bce7a7a95f2b
parent 4237 87d9431243ad
child 4240 6109962761f2
fix error key / field input detection (field's name include -role when specified, the error key *may* include it
web/data/cubicweb.edition.js
--- a/web/data/cubicweb.edition.js	Wed Jan 13 17:44:29 2010 +0100
+++ b/web/data/cubicweb.edition.js	Thu Jan 14 11:12:52 2010 +0100
@@ -328,15 +328,22 @@
     for (fieldname in errors) {
 	var errmsg = errors[fieldname];
 	var fieldid = fieldname + ':' + eid;
-	var field = jqNode(fieldname + ':' + eid);
-	if (field && getNodeAttribute(field, 'type') != 'hidden') {
-	    if ( !firsterrfield ) {
-		firsterrfield = 'err-' + fieldid;
+	var suffixes = ['', '-subject', '-object'];
+	var found = false;
+	for (var i=0, length=suffixes.length; i<length;i++) {
+	    var field = jqNode(fieldname + suffixes[i] + ':' + eid);
+	    if (field && getNodeAttribute(field, 'type') != 'hidden') {
+		if ( !firsterrfield ) {
+		    firsterrfield = 'err-' + fieldid;
+		}
+		addElementClass(field, 'error');
+		var span = SPAN({'id': 'err-' + fieldid, 'class': "error"}, errmsg);
+		field.before(span);
+		found = true;
+		break;
 	    }
-	    addElementClass(field, 'error');
-	    var span = SPAN({'id': 'err-' + fieldid, 'class': "error"}, errmsg);
-	    field.before(span);
-	} else {
+	}
+	if (!found) {
 	    firsterrfield = formid;
 	    globalerrors.push(_(fieldname) + ' : ' + errmsg);
 	}