Validation on ItemEditEnd of Datagrid
I have done validations on ItemEditEnd of datagrid but on
focusout its showinf two alerts. Can anyone specify the
reason?
Can we see some simplified code?
Similar Messages
-
ItemEditEnd not firing in DataGrid
In one particular DataGrid it's not firing - all other in my
app work fine. I've had another Flex developer to look at my code
just in case I'm going mad or something, and he thinks it's a bug
in Flex framework somewhere. I'm using Flex Builder 2.0.1 FWIW
Here is isolated code that exhibits the same behaviour
(breakpoint in onEdit event listener func does not trigger). Much
of it may seem superfluous but in actual app it's neccessary in the
actual app (I just tried to isolate the cause!).
Any ideas?
quote:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
creationComplete="onInit();"
>
<mx:Canvas
xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns:woccu="org.woccu.components.*"
width="100%" height="100%" id="ccc"
paddingTop="0" paddingLeft="0" paddingRight="0"
>
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.events.DataGridEventReason;
import mx.collections.ArrayCollection;
// Dataprovider
private var _dp:ArrayCollection;
// This will contain array (hash) accessible by bottombar or
somesync
[Bindable]
public var bottomBar:Array;
public function onInit():void
_dp=new ArrayCollection([{PK: 'Matt', label: "XXX", col1:
'Matthews', col2: 'XEXE', level: 1}]);;
entrygrid.dataProvider=_dp;
trace('init');
public function refresh():void
// TODO: check if entity ID and other props are not blank!
// Refresh contents or somesync
// Callback function - when the data arrives
protected function onData(result:Array):void
// Builds our dataprovider or somesync
var tmpDPRow:Array;
var _bottomBar:Array=new Array();
_dp=new ArrayCollection();
for ( var j:String in result ) {
// First, check level. If 0 this row belongs to bottombar
if ( result[j]["level"] == "0" ) {
var pk:String=result[j]["PK"];
pk=pk.replace("-","_"); // - is not valid in object ID, so
we replace with _
_bottomBar[pk]=new Object();
_bottomBar[pk]["label"]=result[j]["label"];
_bottomBar[pk]["value"]=result[j]["col2"];
} else {
// Go over fields
tmpDPRow=new Array();
tmpDPRow["PK"]=result[j]["PK"];
tmpDPRow["label"]=result[j]["label"];
tmpDPRow["col1"]=result[j]["col1"];
tmpDPRow["col2"]=result[j]["col2"];
_dp.addItem(tmpDPRow);
// Apply bottom bar
this.bottomBar=_bottomBar;
// Apply all data to datagrid
this.entrygrid.dataProvider=_dp;
public function onEdit(event:DataGridEvent):void {
trace ('fire in the whole!');
if ( event.reason == DataGridEventReason.CANCELLED ) {
return;
// MUST URGENTLY UPDATE frickin database!
this.refresh(); // Subtotals have changed - need refresh
]]>
</mx:Script>
<!--
Note the hack below: column widths are absurdly large values
The idea is that Flex will resize down and keep the
proportions
-->
<mx:DataGrid xmlns:mx="
http://www.adobe.com/2006/mxml"
width="100%" height="100%" showHeaders="false"
itemEditEnd="onEdit(event)" id="entrygrid">
<mx:columns>
<mx:DataGridColumn width="0" visible="false"
dataField="PK">
</mx:DataGridColumn>
<mx:DataGridColumn width="70000"
itemRenderer="mx.controls.TextInput" editable="false"
dataField="label">
</mx:DataGridColumn>
<mx:DataGridColumn width="15000"
itemRenderer="mx.controls.TextInput" editable="false"
dataField="col1">
</mx:DataGridColumn>
<mx:DataGridColumn width="15000"
itemRenderer="mx.controls.TextInput" rendererIsEditor="true"
editable="true" dataField="col2">
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
</mx:Application>Never mind... found the cause. Turns out DataGrid wont fire
itemEditEnd unless it's editable property is true. Of course this
is not documented anywhere... -
Hi all,
I have an application with datagrid inline editing
functionality. I have a custom item renderer for all the columns
and i have to perform validations also on the user entered data.
The itemEditEnd function goes like this,
private function editCell(event:DataGridEvent ) : void
if( event.reason == DataGridEventReason.CANCELLED) {
return;
var oldValue:String =
event.currentTarget.editedItemRenderer.data[event.dataField];
var newValue:String =
TextInput(event.currentTarget.itemEditorInstance).text;
if(newValue == "") {
event.preventDefault();
TextInput(dg.itemEditorInstance).errorString ="Enter a valid
string.";
return;
typical ex from Adobe.
It works fine and shows the error string in the exact edited
text box inside Grid.
But Once i integrate wit the DB with DMS call and tried to
edit, the error message is shown at a random place, say on top of
the page.
please help me out to solve this.
thanks in advanceWorst forums ever! Nobody can help with the insertion of a
currencyvalidator in a datagrid itemeditor? -
Validation of user inputs when using ItemRenderers in DataGrid
Hi,
I have to show multiple editable columns in a DataGrid.
The columns may have different formats and datatypes e.g.
numbers, dates, string etc.
So I am using TextInput/DateField as a ItemRenderer inside
the DataGrid. I have also set the rendererIsEditor="true".
Now I want to apply validation to all these editable columns
depending on their datatypes.
I know I can do that by applying validators individually on
each column.
But is there a way I can use common validation for all the
columns that have a similar datatype or that have the same
renderer?You can use the itemEditEnd Event of the DataGrid for your
validation. Then you can use Actionscript to make sure what the
user enters is in the right format. Example:
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
public function processEdit(event:DataGridEvent):void {
cellValue =
TextInput(event.currentTarget.itemEditorInstance).text; // the
entered text
cell = event.dataField; //the datafield attribute of the
column
// Determine if the new value is too long for nvarchar field
if(cell == 'WLNET' && cellValue.length > 35) {
cellValue = cellValue.substr(0,35); //shortening it for user
demonstrates expected length
TextInput(event.currentTarget.itemEditorInstance).text =
cellValue;
event.preventDefault(); // Prevent the user from removing
focus, and leave the cell editor open.
// Write a message to the errorString property.
// This message appears when the user mouses over the
editor.
TextInput(event.currentTarget.itemEditorInstance).errorString="Entered
text too long.";
return;
]]>
</mx:Script>
<mx:DataGrid id="enrolled_dg" editable="true"
itemEditEnd="processEdit(event);">
I learned part of this from the Flex documentation online:
Determining
the reason for an itemEditEnd event -
Hi,
Is there any way to validate datagrid column or cell.
Please help
Thanks
Kumarquote:
Originally posted by:
peterent
Follow Tracy's advice, but also handle the itemEditEnd event.
In that event handler you can find if the data passed validation.
If it fails you can cancel the edit.
Look up itemEditEnd in the Flex 2 docs. -
Validation on a Datagrid Column
Hi,
I have a Datagrid with three columns, out of which two columns are editable. I want to apply string validator on one of the editable column. How can I do this?You can have a custom ItemRenderer for that column which has a Validator built in. This has been covered in the docs. See this: http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=celleditor_073_17.html
-
Hey guys i have a web app that basically has a browse button and when the user clicks the button it prompts for a file on their PC and loads a datagrid.
My question is rather simple. How do I validate the date columns on datagrid so that it should be formatted like so 17-MAR-10 and not anything other then that. i have a done validation on datagrid with custom classes i built but i have no idea how to go about validating an specific formatt.
Any Help would be greatly appreciated.
Thanks
Migueltwo assumptions:
if you need to show the date in your format - then use itemrenderer or labelfunction.
if you need to show only the rows with that format, then filter the arraycollection - the data provider. -
I use a TextInput ItemEditor in a Datagrid. How do I make
sure the user only inputs numeric input? I can use restrict to get
only integers, but what if I want real numbers with two decimal
places?A simple solution would be to use a Number Validator as seen
here:
http://livedocs.adobe.com/flex/3/html/help.html?content=validators_1.html
:S -
Simple DataGrid validation Problem
hi friends
I am working on a application in which i m facing a problem.i have a datagrid having two column field one is simple datagrid column and in other datagrid column i render textinput as a component. there are only two row in my datagrid.so now i have to apply validation on that data grid.i mean if any textinput componet which is render in second column in data grid left blank and i click on save button then there should be validation Alert messg.
i am facing a problem on gettin id(instance) of that two rendered textinput component.Please help me out.
Thanks and Regards
Vineet OshoHi Vineet Osho,
You can try this...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
>
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
import mx.collections.ArrayCollection;
import mx.controls.TextInput;
import mx.events.DataGridEvent;
import mx.controls.Alert;
public var arr:Array = [];
public var incrementer:int;
private function validateTextInputs():void
var strIndexes:String="";
var gridDP:ArrayCollection = dataGrid.dataProvider as ArrayCollection;
for(var i:int=0;i<gridDP.length;i++)
if(StringUtil.trim(gridDP.getItemAt(i).displayText) == "")
strIndexes += (i + 1) + ",";
if(strIndexes.length > 0)
strIndexes = strIndexes.substring(0,strIndexes.length-1);
Alert.show("The TextInputs " + strIndexes + " are empty.");
]]>
</mx:Script>
<mx:DataGrid id="dataGrid" horizontalCenter="0" verticalCenter="0" width="400" height="200">
<mx:columns>
<mx:DataGridColumn headerText="First" width="60" dataField="artist" editable="false"/>
<mx:DataGridColumn width = "60" headerText = "Premium %(e.g. Percentage as 100)" >
<mx:itemRenderer>
<mx:Component>
<mx:TextInput styleName="TextInputRight" focusOut="data.displayText=this.text;" width="100" text="{data.displayText}">
</mx:TextInput>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
<mx:dataProvider>
<mx:ArrayCollection>
<mx:Array>
<mx:Object title="Stairway to Heaven" artist="Led Zepplin" displayText=""/>
<mx:Object title="How to Save a Life" artist="Fray" displayText=""/>
</mx:Array>
</mx:ArrayCollection>
</mx:dataProvider>
</mx:DataGrid>
<mx:Button id="btn" label="click" x="527" y="450" click="validateTextInputs()" />
</mx:Application>
Thanks,
Bhasker -
Validating user input in a datagrid column
Hi ,
I have 2 datagrid columns for users to enter data. I want to
restrict them only to enter numbers. I tried NumberValidator , that
does not work. Please help !! I am a newbee..
Thanks in advance..We created an itemEditor for our dataColumn that was a
mx:TextInput. Then we used the textInput event to capture keys as
they are typed. You get a TextEvent from that which you can cancel
if it something you don't want the user entering. We used regexs
for are validation here. I'm not sure if this is the best way to
handle this sort of thing, but it worked. -
Editing with a DataGrid and validating user input
Editing
with a DataGrid Tutorial
How to edit the information in a Flex 2 DataGrid directly,
without data binding TextInputs to it.
Uses a Remote Object, a CFC, and a Microsoft Access database
to demonstrate how.
Uses Actionscript to validate the data the user types into
the DataGrid.We created an itemEditor for our dataColumn that was a
mx:TextInput. Then we used the textInput event to capture keys as
they are typed. You get a TextEvent from that which you can cancel
if it something you don't want the user entering. We used regexs
for are validation here. I'm not sure if this is the best way to
handle this sort of thing, but it worked. -
DataGrid and Validation?
I'm having a hard time putting a CurrencyValidator inside of
a DataGrid. The breakpoints would indicate that the data binds
properly, but I get an unfortunately XML mess with big scrollbars
in the datagrid instead of what I'd expect.
Here's the GenericDollarFormatItemRenderer.mxml that
intuition built:
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
public var dataField:String;
[Bindable]
private var dataString:String;
public function newInstance():*
return new GenericDollarFormatItemRenderer();
override public function set data(value:Object):void {
if( value != null ){
super.data = value;
if( !(value is DataGridColumn) && dataField != null
&& value[dataField] != null ){
dataString = value[dataField];
obj:Object;
]]>
</mx:Script>
<mx:CurrencyValidator id="pnV" source="{ti}"
property="text"
trigger="{ti}" triggerEvent="change" required="true" />
<mx:TextInput id="ti" text="{dataString}"
updateComplete="dataString=ti.text;"
change="dataString=ti.text;"/>
</mx:HBox>
I'm adding it to my DataGrid as follows:
[Bindable] private var cf1:ClassFactory = new ClassFactory(
GenericDollarFormatItemRenderer );
cf1.properties = { dataField: 'price' };
<mx:DataGridColumn headerText="price" textAlign="right"
editable="true" itemRenderer="{cf1}" />
The data source for the data grid is e4x XML drawn from an
HTTPService.
Any experts out there can elucidate this one? If I'm on the
completely wrong track, let me know! This is a needed to be done
yesterday type of thing :)
Thanks
AlexWorst forums ever! Nobody can help with the insertion of a
currencyvalidator in a datagrid itemeditor? -
LabelFunction for cell datagrid validation
private function price(item:Object, column:DataGridColumn):String {
if (item.col1.length !=9) { return item.col1 + "error" };
if (item.col2.length > 15){ return item.col2 + "error"};
if (item.col2.length > 10){ return item.col3 ,setStyle("color", 0xff0000) + "error" };
can someone please help me out with this function im trying to validate the items on a datagrid for lenght of theirs string but when i try to do it this way i get really bad errors.
<mx:DataGridColumn headerText="Vendor Number" dataField="col1" itemRenderer="PriceLabel" />
<mx:DataGridColumn headerText="Invoice Number" dataField="col2" itemRenderer="PriceLabel"/>
<mx:DataGridColumn headerText="Invoice Date" dataField="col3" />
i like to validate each column separetely but its seems to try to do it all at once.
Any help would be greatly appreciated.
Thanks
youTry using else if for the last two if statements.
But you should probably check the column first, then do the formatting, using the column parameter.
I'll show you how if you don't know. -
Comparing two columns in a datagrid.
I have a datagrid that has a data provider of some users. The users have a name, address, balance, and payment amount. For the payment amount I'm using a custom MXDataItemRenderer as my TextEditor (not text renderer). What I want to do is validate that the amount they entered in the payment amount is not greater than the balance.
I've been trying to do this on an itemEditEndHandler, but the problem is that for some reason I don't have the payment amount at that time. I'm wondering what I'm doing wrong or if I'm going about this completely the wrong way.
Any help would be greatly appreciated.
Thanks
Here is my editHandler function
var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
var paymentValidator:PaymentAmountValidator = new PaymentAmountValidator(item.balance);
paymentValidator.source = this.dataProvider;
paymentValidator.property = "paymentAmount";
paymentValidator.validate(item.paymentAmount);
Here is my custom validator.
public class PaymentAmountValidator extends Validator
private var results:Array;
private var balance:Number;
public function PaymentAmountValidator(balance:Number = 0){
super();
this.balance = balance;
// Define the doValidation() method.
override protected function doValidation(value:Object):Array {
// Convert value to a Number.
var inputValue:Number = Number(value);
// Clear results Array.
results = [];
// Call base class doValidation().
results = super.doValidation(value);
// Return if there are errors.
if (results.length > 0)
return results;
// If input value is not a number, or contains no value,
// issue a validation error.
if (isNaN(inputValue) || !value )
results.push(new ValidationResult(true, null, "NaN",
"You must enter an amount."));
return results;
if (inputValue > balance) {
results.push(new ValidationResult(true, null, "moreThanBalance",
"Payment amount must be less than or equal to balance."));
return results;
return results;Thanks for the answer. I ended up doing it a little differently and instead of catching the itemEditEnd event I added my custom validator to the actual renderer itself, but your advice to use the itemEditorInstance got me the data I needed.
My validation looked like this before moving it to the custom item editor.
var item:Object = ((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex];
var amountText:String = AmountTextInputRenderer(this.itemEditorInstance).amountText;
var paymentValidator:PaymentAmountValidator = new PaymentAmountValidator(parseFloat(amountText));
paymentValidator.source = item;
paymentValidator.property = "paymentAmount";
paymentValidator.validate(item.paymentAmount); -
hi i have a little proble with my application and i need some
help i'll like to valide a field of a data gridcolunm and i dont
know how to do for example
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script >
<![CDATA[
import mx.collections.ArrayCollection;
private var Anagrafica:ArrayCollection = new
ArrayCollection;
]]>
</mx:Script>
<mx:DataGrid id = "mydatagrid"x="222" y="156"
dataProvider="{Anagrafica}">
<mx:columns>
<mx:DataGridColumn headerText="Nome" dataField="nome"
editable="true"/>
<mx:DataGridColumn headerText="Email" dataField="mail"
editable="true"/>
<mx:DataGridColumn headerText="Telefono" dataField="tel"
editable="true"/ >
</mx:columns>
</mx:DataGrid>
<mx:StringValidator id="stingval" source="{}" />
<mx:PhoneNumberValidator id="phoneval" source="{}"/>
<mx:EmailValidator id="emailval" source="{}"/>
</mx:Application>
i want to validate the value of the field email of mydatagrig
with the emailvalidator it is possible ? i tried to put an id to
the filed
<mx:DataGridColumn headerText="Nome" dataField="nome"
editable="true" id ="test"/ > and give it to "source"
<mx:EmailValidator id="emailval" source="{test}"/> but
it doesnt work hellpppppp
sorry for my englishYour English is fantastic! Don't worry about it!
Now, onto the solution! Here is *one* way you can do it:
register an event handler for itemEditEnd event
public function itemEditEndHandler(event:DataGridEvent) :
void {
var newData:String =
TextInput(event.currentTarget.itemEditorInstance).text;
if (!Number(newData)) {
event.preventDefault();
TextInput(this.blocksDataGrid.itemEditorInstance).errorString =
"Please enter a valid number between 0 and 100.";
return;
so essentially you validate data either thru a validator or
just by plain IF statemetments, and if it fails you preventDefault
on the event and assign an error message to the editor.
Another way of doing it would be to write you editor.
Yet another way of doing it would be to do it itemFocusOut
event.
Hope this get you started.
ATTA
Maybe you are looking for
-
I just got to school after getting a new screen put on my 13in macbook pro. when i opend up my macbook there was only a apple simble and the loading sing with a bar at the botton it took fovere to load, one it loaded and opend up there was a few opti
-
Error while generate export datasource.
Hi Experts, APO - 3.0A(BW-2.0A) In APO while creating generate export datasource for a cube, I am getting the following error. Creation of InfoSource 8XXX for target system BW 1.2 failed - Message no. RSBM 026 Diagnosis - Failed to create InfoSource
-
How do i customize a ringtone with a track I purchased in the play store?
I purchased a track through the play store but when I open the music app (the white cirlce with the green music note) the track doesn't show up. I tried looking for the sync music option under settings but no luck. The track shows up in the play musi
-
Query on IDOC Ack (STATUS) config in XI for a specific partner comm.
Hi Experts, Is it possible to configure the IDOC Ack (STATUS.SYSTAT01 message) in XI for a specific partner communication? We want to configure our system like ALEAUD but the message type should be STATUS.SYSTAT01 and the acknowledgment should be sen
-
Sort in iTunes 10 column "Album Artist"
Hello, I have a question regarding the sorting options in the iTunes Library. I have add a couple of albums which I have tagged accurately. If I sort by "Album by artist" it goes correct. It shows the albums sorted by artist. If I sort by "Album arti