Custom inputControl remembers previous value

Posted by: prubhjot.randhawa on 20 August 2021, 11:23 am EST

    • Post Options:
    • Link

    Posted 20 August 2021, 11:23 am EST

    When creating a custom control for inputs on my column (in flexgrid) for number values, it achieves the desired affect of displaying commas for large numbers as you type. However after modifying a value for example in column a row 1 and saving it, when adding a new row upon click of the new cell in column a the value from row 1 is inserted by default. Please see video attached with a demo of the issue

    
        private convertNumberColumnsToNumberInputs(): void {
            if (!this.useInputNumberEditor) {
                return;
            }
    
            this.grid.columns.forEach((col: Column) => {
                const colFormat = col.format;
                if (colFormat && !col.dataMap && colFormat.startsWith('n')) {
                    col.editor = new InputNumber(document.createElement('div'), {
                        format: col.format
                    });
                    (col.editor as InputNumber).inputElement.className += ' editable-cell';
                }
            });
        }
    
    

    Bug.zip

  • Posted 23 August 2021, 11:32 pm EST

    Hi,

    As per my observation of your code, the issue you are facing is not a bug. You are inserting the input control to the columns having certain conditions, but here the catch is that the inputNumber control is created once and whenever you are editing that column’s cell, the instance of the same inputNumber is fetched, and as the control already has a value from the last editing, so the above scenario is produced. To resolve the issue you may set the value to null and the isRequired property to false.

    You may also refer to the sample demonstrating the same:

    https://stackblitz.com/edit/angular-7npzwn

    Regards,

    Ashwin

  • Posted 24 August 2021, 7:12 am EST

    Hi Ashwin,

    Perfect that solves my issue, thank you very much!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels