简体   繁体   English

SASS隔离和HTML5表单验证问题

[英]SASS Isolation with HTML5 Form Validation Issue

I isolated the CSS with Bootstrap 4 using this SASS: 我使用此SASS隔离了Bootstrap 4的CSS:

.iso-bootstap {
  @import "bootstrap";
}

That imported all of bootstrap css with .iso-bootstap in front of all the elements isolating it so I can only use bootstrap within a div with the class of "iso-bootstrap". 那将所有带有.iso-bootstap的bootstrap css导入到所有隔离它的元素之前,所以我只能在div中使用“ iso-bootstrap”类使用bootstrap。

I've noticed this has rendered the following validation JavaScript useless. 我注意到这使以下验证JavaScript无效。 I'm not too JavaScript savvy to know how to modify the JavaScript to understand what the CSS is doing now that .iso-bootstap is applied before everything. 我不太懂JavaScript,现在知道.iso-bootstap应用于所有内容之前,如何修改JavaScript以了解CSS的功能。

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>window.jQuery || document.write('<script src="http://getbootstrap.com/assets/js/vendor/jquery-slim.min.js"><\/script>')</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script type="text/javascript">
  // Example starter JavaScript for disabling form submissions if there are invalid fields
  (function() {
    'use strict';

    window.addEventListener('load', function() {
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
      var forms = document.getElementsByClassName('needs-validation');

      // Loop over them and prevent submission
      var validation = Array.prototype.filter.call(forms, function(form) {
        form.addEventListener('submit', function(event) {
          if (form.checkValidity() === false) {
            event.preventDefault();
            event.stopPropagation();
          }
          form.classList.add('was-validated');
        }, false);
      });
    }, false);
  })();
</script>

If someone could help me out and point me in the right direction or help me fix this, that would be greatly appreciated! 如果有人可以帮助我并指出正确的方向或帮助我解决此问题,将不胜感激!

Thanks in advance! 提前致谢!

I figured out my issue. 我知道了我的问题。 For anyone using SASS to isolate bootstrap into a class. 对于使用SASS将引导程序隔离到类中的任何人。 My problem was that my compiler, CodeKit, compiled and implimented classes for the validation backwards. 我的问题是我的编译器CodeKit向后编译和隐含了用于验证的类。 So ".was-validated .iso-bootstap" needed to be ".iso-bootstap .was-validated". 因此,“。was-validated .iso-bootstap”需要为“ .iso-bootstap .was-validated”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM