Jump to content

Forbid adding 0


Recommended Posts

I have a tabular report with inline add and edit options enabled. 
Due to the logic of my application, I cannot accept  0 (zero) as a value in one of number inputs.
To restrict adding 0 while adding new or editing existing values in tabular report, I used the following script:

<script>
if(typeof enforceNoZeroInput == 'undefined') {
const inputAddName = 'InlineAddInteger_1'
const inputEditName = 'InlineEditInteger_1'
const enforceNoZeroInput = () => { 
 document.addEventListener('input', (e)=>{  
  if (e.target.getAttribute('name').indexOf(inputAddName) > -1 || e.target.getAttribute('name').indexOf(inputEditName) > -1) {
    if (e.target.value == '0' ) {
        e.target.value = ''
        alert('zero value is forbidden')
    }}}, true)
document.removeEventListener('DataPageReady', enforceNoZeroInput )}
document.addEventListener('DataPageReady', enforceNoZeroInput )
}
</script>

Where "InlineAddInteger_1"  is the name of the input in inline add section of tabular report where 0 is not allowed
And "InlineEditInteger_1" is the name of the input in inline edit section of tabular report where 0 is not allowed
You can find names of your inputs in the source code when inspecting them in your browser

image.thumb.png.e75faa6923854e3bc9fecf317a73254f.png

image.thumb.png.ae41f990422e19acd6a0b00d4734c503.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...