Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate DataGridColumn cells individually
    text
    copied!<p>How can I validate the cells in a DataGridColumn individually? (ActionScript 3.5) The validation is configured per-cell, based on fields in the given row. For example</p> <pre><code>FIELD VALUE TYPE age 13 Integer height 13x3 Integer registered true Boolean temperature 98.G6 Float </code></pre> <p>In this case, of course 13x3 and 98.G6 would be invalid. </p> <p>It's easy to write a <em>Validator</em> ; and to access the data provider objects.</p> <p>But how do I get individual access to the GUI cell objects so I can set the <em>errorString</em> on an individual cell, either directly or through a <em>Validator</em>?</p> <p>The <em>itemRenderer</em>/ <em>TextInput</em> control is re-used across the cells for performance reasons, so accessing the GUI-level objects is tricky.</p> <hr> <p>Edit</p> <p>Answers: </p> <ol> <li><p>One way to validate and display the invalidation markings, but not per-cell, is to validate all data-provider objects and then set the <em>errorString</em> on the entire grid.</p></li> <li><p>One way to validate per-cell is on the <em>itemEditEnd</em> event handler. (See these pages <a href="http://www.adobe.com/devnet/flex/articles/itemeditors_pt2.html" rel="nofollow noreferrer">A</a> <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html" rel="nofollow noreferrer">B</a> <a href="http://blogs.digitalprimates.net/strictinequality/index.cfm/2008/3/3/Datagrid-item-editors-and-dynamic-behavior-part-23" rel="nofollow noreferrer">C</a> <a href="http://www.badu.ro/?p=37" rel="nofollow noreferrer">D</a>). One disadvantage is that it only allows access to the cells from the "inside", not in an action that validates the grid on command.</p></li> <li><p>A custom <em>itemRenderer</em> is another possibility, as in the answer below, but like 3 above, it only allows access to the cells from the "inside", not in an action that validates the grid on command.</p></li> <li><p>See Richard Haven's answer below.</p></li> <li><p>And here's <a href="http://www.switchonthecode.com/tutorials/accessing-datagrid-itemrenderers" rel="nofollow noreferrer">how to access the GUI objects</a>: The list of relevant GUI objects is a protected field; so you can access it by subclassing, then iterate over the GUI-components which represent the cells and set the <em>errorString</em> on each one. </p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload