Add itemEditorValidatorFunction with Pop up window confirmation to Flexicious Grid

114 Views Asked by At

I am trying to have my Flexicious DataGrid ask for confirmation of a change when I click in a cell to edit a value and enter a new value which deviates from the original by a certain percentage. I cannot see an easy way to do this. Initially, I tried to write a itemEditorValidatorFunction, which returns a boolean. This works perfectly for a hard coded return value, but if I try to take the return value from the CloseEvent of an Alert, that value is ignored:

    protected function validateGcCap(editor:UIComponent):Boolean{
        var warningBPDiffVal:Number = Number(5);
        var warningPerCentDiffVal:Number = Number(warningBPDiffVal / 1000);
        var allowChange:Boolean = true;
        var origGcCapVal:Number = Number(managerGrid.getCurrentEditingCell().text);
        var newGcCapVal:Number = Number((editor as TextInput).text);
        var diffVal:Number = Number(newGcCapVal - origGcCapVal);

        if (origGcCapVal > newGcCapVal) {
            diffVal = origGcCapVal - newGcCapVal;
        }

        if (diffVal > warningPerCentDiffVal) {
            //Alert.show("you changed the gccap from " + origGcCapVal + " to " + newGcCapVal + " by " + diffVal);

            function alertCloseHandler(event:CloseEvent):void{
                if (event.detail == Alert.CANCEL) {
                    allowChange = false;
                }
            };

            var alert:Alert = Alert.show("Are you sure that you want to update gcCap% by more than " + warningBPDiffVal + "bps?",
                    "Please Confirm", (Alert.OK | Alert.CANCEL),
                    this, alertCloseHandler);
       }

        return allowChange;
    }

I also tried to write a itemEditor for the grids:FlexDataGridColumn, where I extended com.flexicious.controls.TextInput, but I could not work out which method to override. I wanted to override the method and only make the call to super if the Alert was clicked OK, but I could not see which method I should override. I tried override protected function onTextInput(textEvent:TextEvent):void, but this did nothing.

I would be grateful for any insight into this problem.

2

There are 2 best solutions below

1
On BEST ANSWER

This is what works:

    private function validateGcCap(editor:UIComponent):Boolean{
        var warningBPDiffVal:Number = Number(5);
        var cell:IFlexDataGridCell = managerGrid.getCurrentEditingCell();
        var warningPerCentDiffVal:Number = Number(warningBPDiffVal / 1000);
        var origGcCapVal:Number = Number(cell.text);
        var newGcCapVal:Number = Number((editor as TextInput).text);
        var diffVal:Number = Number(newGcCapVal - origGcCapVal);

        if (origGcCapVal > newGcCapVal){
            diffVal = origGcCapVal - newGcCapVal;
        }

        if (diffVal > warningPerCentDiffVal){

            function alertCloseHandler(event:CloseEvent):void{
                if (event.detail == Alert.CANCEL) {
                    IAParamsVO(cell.rowInfo.data).gcCapWrapper = origGcCapVal;
                    managerGrid.refreshCells();
                }
            }

            Alert.show("Are you sure that you want to update gcCap% by more than "
                               + warningBPDiffVal + "bps?", "Please Confirm", (Alert.OK | Alert.CANCEL),
                    this, alertCloseHandler);
        }

        return true;
    }
3
On

Not sure why someone decided to downvote your question, it seems quite valid. From looking at this, the best way for you would be to "undo" the edit when the user selects no on the box. If you have enableTrackChanges on, all you have to do is to remove that change from the dgGrid.changes collection and call dgGrid.refreshCells(). If you dont have enableTrackChanges, all you need to do is to update the dataProvider row with the old value, call dgGrid.refreshCells() and you should be set.