Google script HTML select required did not work

感情迁移 提交于 2021-01-29 08:21:56

问题


Code (I'm working with Materialize CSS framework):

<form class="col s12" id="formRequer">     
      <div class="input-field col s6">
        <select id="stdApply" name="stdApply" required>
          <option value="" disabled selected>Escolha somente uma das opções</option>
          <option value="1">Option 1</option>
          <option value="2">Option 2</option>
          <option value="3">Option 3</option>
        </select>
        <label>Selecione o que quer requerer</label>
      </div>      
  </form>   <!-- END: form class="col s12" id="formRequer -->  


<button class="btn waves-effect waves-light" type="submit" id="btn_submitRequer" form="formRequer">Enviar
  <i class="material-icons right">send</i>
</button>

I copied the code excluding CSS and paste it on w3school and it worked fine!

Is it possible that HTMLService evalute() process exclude the required attribute from tag or exclude the value="" attribute from the first option (this is vital for HTML5 select tag works with required attribute)?

Any help?


回答1:


Try this:

HTML:

<html>
<head></head>
<body>
  <form>     
   <select id="stdApply" name="stdApply">
     <option value="" selected>Escolha somente uma das opções</option>
     <option value="1">Option 1</option>
     <option value="2">Option 2</option>
     <option value="3">Option 3</option>
   </select>
   <label>Selecione o que quer requerer</label>
   <br /><input type="button" value="Enviar" onClick="processForm(this.parentNode);" />
  </form>  
  <script>
    function processForm(obj) {
      if(obj.stdApply.value!='') {
        google.script.run.processForm(obj);
      }else{
        document.getElementById('stdApply').focus();
      }
    }
  </script>
</body>
</html>

Google Script:

function processForm(obj) {
  Browser.msgBox(obj.stdApply);
}

function showMyDialog() {
  SpreadsheetApp.getUi().showModelessDialog(HtmlService.createHtmlOutputFromFile('ah3'), 'Test');
}


来源:https://stackoverflow.com/questions/61594967/google-script-html-select-required-did-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!