Restrict the edited item to a s

Posted by: mothydharan on 15 September 2017, 5:47 am EST

  • Posted 15 September 2017, 5:47 am 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?
  • Replied 19 September 2017, 1:07 am 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
  • Replied 23 November 2017, 2:03 am 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
Need extra support?

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

Learn More

Forum Channels