How to handle "input is not focusable" in javascript form validation?
P粉208469050
P粉208469050 2023-08-01 19:38:54
0
1
476
<p>I have this control</p> <p><br /></p> <pre class="brush:html;toolbar:false;"><div class="conico"> <input class="form-control" readonly id="fileName"/> <input class="form-control" type="file" style="display:none;" required="xxx" id="fileSelect"/> <label for="xxx" class="ico"> <img src="/images/icocamera.svg"> </label> </div></pre> <p><br /></p> <p>I want to fill the textbox with the file name. In the above code, each file has an icon. When the icon is pressed, the corresponding filename should be populated into the input. <br /><br />This works fine, but when the user doesn't select a file and then submit they get an error:</p><p><br />< ;/p> <blockquote> <p>input is not focusable</p> </blockquote> <p>How can I handle this error using a custom javascript function?</p>
P粉208469050
P粉208469050

reply all(1)
P粉897881626

fileName needs required = true, not a file selector.

Then you can do this:


$( "form" ).on( "submit", function( event ) {
  if ( $( "#fileName" ).val() ) {
    return;
  }
 
  console.log('not valid')
  event.preventDefault();
} );
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template