Restrict the edited item to a s

Posted by: mothydharan on 14 September 2017, 8:47 pm EST

  • Posted 14 September 2017, 8:47 pm EST

    Hi,

    In the wijmo grid , we have a number format column which displays data as 12345.1234567891 (digits+10 decimal values). This column can have less number of decimal points as well like 12.34.

    When the column comes into an edited mode, we want the user to restrict the entry to 10 decimal digits and not beyond that.We have used the mask property from wijmo forum as ‘mask:000.0000000000’.But it is not allowing me to save data if it has less than ten number of decimal values or greater than three digits. It always restricts the user to enter 3 digits and 10 decimal places. Can you guys please help me to achieve this?

  • Posted 18 September 2017, 4:07 pm EST

    Hi MothyDharan,

    As you MASK can be used only when you would like to enter string in a specific pattern. Here, you need to handle keydown event and validate using RegularExpression. Please refer to the following code snippet for the same:

    
    flex.hostElement.addEventListener("keydown",function(e){               
                    const regex = /(\d*\.\d{10})/g;       
                    var str = flex.activeEditor.value;
                    let m;               
                    while ((m = regex.exec(str)) !== null) {
                        // This is necessary to avoid infinite loops with zero-width matches
                        if (m.index === regex.lastIndex) {
                            regex.lastIndex++;
                        }
                        console.log(m)
                        if(m.length==2){                        
                            e.preventDefault();
                        }                    
                    }
                    
                },true);
    
    

    It should work!

    Thanks,

    Manish Kumar Gupta

  • Posted 22 November 2017, 5:03 pm EST

    Hi Manish,

    I have seen that there is a property called maxLength in the document.But iam unable to find the same in the column properties.Please see the attached screenshot. Hoping that maxLength will solve the issue

    Hoping to get reply soon.

    -Thank you

  • Posted 29 October 2018, 4:21 pm EST

    Hi Manish,

    This example works fine when doing it for the first time.

    Once the match is found like, 1.1234567891, then if I try and add something like, 12.1234567891. This does not enter a value.

    So, this prevent adding any character before or after the decimal point.

    Is there any solution to this?

    Thanks,

    Brijesh

Need extra support?

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

Learn More

Forum Channels