Remove focus the cell when popup invalid formula is showing

Posted by: dnguyenthanhtu on 14 November 2022, 6:11 pm EST

  • Posted 14 November 2022, 6:11 pm EST

    I have some issue when the popup invalid formula is showing, I can edit the cell in the sheet. I need to when the popup in invalid formula is showing, I can’t edit the cell in the sheet. I’m thinking I find the event to show popup and remove the focus. Please help me

  • Posted 14 November 2022, 6:12 pm EST

  • Posted 16 November 2022, 4:34 am EST

    Hi,

    When the formula is invalid, the InvalidOperation Event is triggered.

    When an invalid formula is entered, you can use the focus method to remove the focus from the SpreadJS.

    Please see the following code example:

    
    spread.bind(GC.Spread.Sheets.Events.InvalidOperation, function (sender, args) {
        if (args.invalidType === GC.Spread.Sheets.InvalidOperationType.setFormula) {
            setTimeout(() => {
                spread.focus(false);
            })
        }
    })
    

    Sample: https://jscodemine.grapecity.com/share/JF8KcrZdbE6RN_NfE22Vdg/

    References:

    InvalidOperation Event: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Events#invalidoperation

    focus method: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Workbook#focus

    InvalidOperationType Enumeration: https://www.grapecity.com/spreadjs/api/enums/GC.Spread.Sheets.InvalidOperationType

    Regards,

    Ankit

  • Posted 16 November 2022, 9:30 pm EST

    Why we need to use the setTimeout function, and we don’t sent any parameter (ex: timeout)?

  • Posted 17 November 2022, 10:25 pm EST

    Hi,

    When a callback is provided as the second argument to setTimeout, zero, the callback will be scheduled to run asynchronously and with the smallest possible delay.

    When the Invalid Operation occurs, there is a race condition between your code to make SpreadJS the focus and the attempt to modify the Dialog Popup message and show it. And when the Dialog Warning is displayed, the code to make SpreadJS the focus will once again cause SpreadJS to lose this race (current behavior).

    SetTimeout(cb, 0) causes SpreadJS to focus in the shortest amount of time while the Dialog Warning is already displayed up until that point. When spread.focus(false) is used, it causes the SpreadJS to lose focus, which is the desired outcome.

    Regards,

    Ankit

Need extra support?

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

Learn More

Forum Channels