Select 无法与 jQuery Steps 一起正常工作

问题描述 投票:0回答:2

所以我正在使用 jQuery Steps 制作一个表单,但选择无法正常工作。当我从下拉列表中选择时,什么也没有发生。默认选项仍然是选定的选项。

我使用 https://developer.snapappointments.com/bootstrap-select/ 进行选择。

js代码:

$('#wizard_vertical').steps({
    headerTag: 'h3',
    bodyTag: 'section',
    transitionEffect: 'slideLeft',
    stepsOrientation: 'vertical',
    onInit: function (event, currentIndex) {
        setButtonWavesEffect(event);
    },
    onStepChanged: function (event, currentIndex, priorIndex) {
        setButtonWavesEffect(event);
    }
});

此外,选择在表单之外也能正常工作。

我真的不知道如何解决这个问题,所以我们将不胜感激。

html jquery twitter-bootstrap jquery-steps
2个回答
0
投票

我似乎也遇到了同样的问题,你找到解决方案了吗?

我自己进行了故障排除,并得出了相同的结论:选择不显示预选值,也不显示表单中的任何其他选定选项;但在表单之外,它确实工作正常并按预期显示所选值。

这些是我的内容:

<link rel="stylesheet" 
    href="https://cdn.materialdesignicons.com/4.8.95/css/materialdesignicons.min.css"/>
<link rel="stylesheet" 
    href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"/>
<link rel="stylesheet" href="assets/css/bd-wizard.css" />
<link rel="stylesheet" href="assets/css/config.css" />
...
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!-- jQuery Steps Version: v1.1.0 -->
<script src="assets/js/jquery.steps.min.js"></script>
<script src="assets/js/bd-wizard.js"></script>

bd-wizard.css:

body {
  font-family: "Karla", sans-serif;
  background-color: #f2f3f8;
}

/* Wizard */
.wizard a:hover {
  text-decoration: none;
}

.wizard .audible {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.wizard .steps > ul {
  list-style: none;
  padding-left: 0;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: justify;
  justify-content: space-between;
  margin-bottom: 0;
}
.wizard .steps > ul li {
  width: 270px;
  max-width: calc(15% - 3px);
}
.wizard .steps > ul li a {
  display: inline-block;
  width: 100%;
  height: 100%;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
  background-color: rgba(153, 155, 163, 0.1);
  padding: 28px 30px 24px;
}
@media (max-width: 767px) {
  .wizard .steps > ul li a {
    padding: 15px 10px;
  }
}
/* @media (max-width: 767px) {
  .wizard .steps > ul li a .media {
    display: block;
  }
} */

.wizard .steps > ul li .bd-wizard-step-title {
  line-height: 1;
  font-size: 18px;
  font-weight: bold;
  color: #000000;
}
/* @media (max-width: 767px) {
  .wizard .steps > ul li .bd-wizard-step-title {
    display: none;
  }
} */
.wizard .steps > ul li .bd-wizard-step-subtitle {
  line-height: 1;
  font-size: 14px;
  color: #c8c8c8;
}
@media (max-width: 767px) {
  .wizard .steps > ul li .bd-wizard-step-subtitle {
    display: none;
  }
}

.wizard .steps > ul li.current a {
  background-color: #fff;
}

.wizard .content {
  padding: 100px 35px 20px 35px;
  background-color: #fff;
  min-height: 420px;
}
@media (max-width: 767px) {
  .wizard .content {
    padding-left: 20px;
    padding-right: 20px;
    min-height: auto;
  }
}
.wizard .content .title {
  display: none;
}
.wizard .content .content-wrapper {
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}
.wizard .content .section-heading {
  font-weight: bold;
  color: #030303;
  margin-bottom: 22px;
}
.wizard .content p {
  font-size: 16px;
  color: #030303;
}
.wizard .content .form-control {
  padding: 26px 25px;
  min-height: 50px;
  max-width: 550px;
  border-radius: 4px;
  border: solid 1px #ececec;
}
.wizard .content .form-control::-webkit-input-placeholder {
  color: #919aa3;
}
.wizard .content .form-control::-moz-placeholder {
  color: #919aa3;
}
.wizard .content .form-control:-ms-input-placeholder {
  color: #919aa3;
}
.wizard .content .form-control::-ms-input-placeholder {
  color: #919aa3;
}
.wizard .content .form-control::placeholder {
  color: #919aa3;
}

.wizard .actions {
  padding: 0 35px 35px;
  background-color: #fff;
}
@media (max-width: 767px) {
  .wizard .actions {
    padding-left: 20px;
    padding-right: 20px;
  }
}
.wizard .actions > ul {
  list-style: none;
  padding-left: 0;
  display: -webkit-box;
  display: flex;
  -webkit-box-pack: end;
  justify-content: flex-end;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 15px;
  border-bottom: 1px solid #f5f5f4;
}
.wizard .actions li a {
  display: inline-block;
  border-radius: 6px;
  background-color: #00d69f;
  padding: 16px 30px;
  color: #fff;
  font-style: 15px;
  font-weight: bold;
}
.wizard .actions li.disabled {
  display: none;
}
.wizard .actions li:not(.disabled) + li,
.wizard .actions li:not(:first-child):last-child {
  margin-left: 15px;
}

配置.css:

ul {
  list-style-type: none;
}

li {
  display: inline-block;
}

input[type="radio"][id^="cb"] {
  display: none;
}

label {
  padding: 10px;
  display: block;
  position: relative;
  margin: 10px;
  cursor: pointer;
}

label:before {
  background-color: white;
  color: white;
  content: " ";
  display: block;
  border-radius: 50%;
  border: 1px solid grey;
  position: absolute;
  bottom: 0px;
  width: 25px;
  height: 25px;
  text-align: center;
  line-height: 28px;
  transition-duration: 0.4s;
  transform: scale(0);
}

label img {
  height: 150px;
  width: 150px;
  transition-duration: 0.2s;
  transform-origin: 50% 50%;
}

:checked + label {
  border-color: #ddd;
}

:checked + label:before {
  content: "✓";
  background-color: #4caf50;
  transform: scale(1);
}

:checked + label img {
  transform: scale(0.9);
  box-shadow: 0 0 5px #4caf50;
  z-index: -1;
}

select {
  color: black;
}

bd-wizard.js 包含 Steps 插件的初始化:

//Wizard Init
$("#wizard").steps({
    headerTag: "h3",
    bodyTag: "section",
    transitionEffect: "none",
    titleTemplate: '#title#',

    labels: {
        next: "Weiter",
        previous: "Zurück"
    }
});

HTML:

<body>
  <main class="my-5">
    <form name="contact" id="contact" action="submit.php" method="POST">
      <div class="container">
        <div id="wizard">
          ...
          <h3>
            <div class="media">
              <div class="media-body">
                <div class="bd-wizard-step-title">Gr&ouml;&szlig;e</div>
                <div class="bd-wizard-step-subtitle">Schritt 4</div>
              </div>
            </div>
          </h3>
          <section>
            <div class="content-wrapper">
              <h4 class="section-heading">
                Wie viel Wohn- und Grundst&uuml;cksfl&auml;che hat Ihre
                Immobilie?
              </h4>
              <div class="container">
                <div class="form-row">
                  <div class="form-group col-sm-12">
                    <span class="control-label">Wohnfl&auml;che</span>
                    <select class="form-control" name="living_size">
                      <option disabled selected>Bitte auswählen</option>
                      <option value="test">unter 200 &#13217;</option>
                      <option value="test2">200 - 400 &#13217;</option>
                      <option value="test3">&uuml;ber 400 &#13217;</option>
                      <option value="test4">Kann ich nicht genau sagen</option>
                    </select>
                  </div>
                  <div class="form-group col-sm-12">
                    <span class="control-label">
                      Grundst&uuml;cksfl&auml;che
                    </span>
                    <select class="form-control" name="property_size">
                      <option disabled selected>Bitte auswählen</option>
                      <option>unter 300 &#13217;</option>
                      <option>300 - 1.000 &#13217;</option>
                      <option>&uuml;ber 1.000 &#13217;</option>
                      <option>Kann ich nicht genau sagen</option>
                    </select>
                  </div>
                </div>
              </div>
            </div>
          </section>
          ...
        </div>
      </div>
    </form>
<!-- This select works as expected -->
    <span class="control-label">Wohnfl&auml;che</span>
    <select class="form-control" name="living_size">
      <option disabled selected>Bitte auswählen</option>
      <option value="test">unter 200 &#13217;</option>
      <option value="test2">200 - 400 &#13217;</option>
      <option value="test3">&uuml;ber 400 &#13217;</option>
      <option value="test4">Kann ich nicht genau sagen</option>
    </select>
  </main>
...
</body>

0
投票

jquery-steps 初始化后,使用 javascript 加载 selectpicker

HTML

<div class="form-group">
    <label for="lst-currency">Currency</label>
    <select class="form-control" id="lst-currency" title="Currency (All)">
    </select>
</div>

Javascript

// initialize your steps wizard
initSteps();

// initialize selectpicker element with JS

let options = [];
options.push('<option value="MMK">MMK</option>');
options.push('<option value="USD">USD</option>');
$("#lst-currency").html(options).selectpicker('refresh');

或者直接调用 refresh 方法

HTML

<div class="form-group">
    <label for="lst-currency">Currency</label>
    <select class="form-control" id="lst-currency" title="Currency (All)">
     <option value="MMK">MMK</option>
     <option value="USD">USD</option>
    </select>
</div>

Javascript

// initialize your steps wizard first
initSteps();

// call 'refresh' method of bootstrap-selectpicker   
$("#lst-currency").selectpicker('refresh');
© www.soinside.com 2019 - 2024. All rights reserved.