-
24 Feb 2012 4:51 AM #1
Additional Error Labels in Ext.FromPanel
Additional Error Labels in Ext.FromPanel
Hi Guys,
im currently trying to connect extjs4 with cakephp and i want to display the server validation errors of cakephp as label behind the the fields that didnt validate.
i already have the field's names and the validation errors, and ext detects whether it was successful or not (Form.submit -> success => true....)
All i have to do now, is showing them in some kind of labels behind the apporopriate fields.
My Question: Is the a way to add divs behind each input field ? Or is the a workaround or best practice concerning this topic ? Im pretty new with Ext and i'm currently fighting
Thanks in Advance
Duderion
-
24 Feb 2012 5:51 AM #2
take a look at:
http://docs.sencha.com/ext-js/4-0/#!...-cfg-msgTarget
the value "side" seems to fit best. then you will get red error icons at the right side of your field displaying a tooltip with the current error message. this works fine to display server side errors.
in case none of the options fulfill your needs, you will have to create a custom one.
-
16 Mar 2012 3:34 AM #3
Could anyone tell me how to access the msgTargets to fill it manually ?
i have to write my own validation message in there.
i try to find it through the DOM, but i can't get it yet
i already have the fields
error[1] is my validation error message, that i want to put into the msgTargetCode:var error = String(obj.errors.reason[x]).split(','); var field = Ext.select('input[name="data[User]['+error[0]+']"]');
sorry, i'm pretty new to extjs
duderion
-
29 Mar 2012 3:42 AM #4
I found a solution..
as the error have a class like 'blabla-errorEl' i could easily find them by Ext.get and do a field.update to write in the appropriate error message from the model validation.
the model name (here ist is User) is still hardcoded, but you could write a function to the controller, that tells the view, which model is used.
the Controller Code is
the Ext4 View:Code:if ($this->User->save($this->data)) { return json_encode(array('success' => 'true')); } else { $errors = $this->User->invalidFields(); $response_errors = array(); foreach ($errors as $field => $e) { $response_errors[] = array($field, $e[0]); } $response = '{success: false, errors: { reason: '. json_encode($response_errors).' }}'; return $response; }
cyaCode:buttons: [{ text:'Add User', handler: function() { addpanel.getForm().submit( { url: '/test/users/add', success: function(form,action) { alert('true'); }, failure: function(form,action) { var obj = Ext.decode(action.response.responseText); for (x in obj.errors.reason) { var error = String(obj.errors.reason[x]).split(','); var field = Ext.get('data[User]['+error[0]+']-errorEl'); field.update(error[1]).show(); } } }) } }]
dude


Reply With Quote