Repeat Selectize select field












1














I have a form where the user can input multiple addresses, city, street+nbr and country.



For this field to be repeated I use the jquery repeater library. For the city field I want to use a selectize input field.



I am trying to repeat those 4 fields when clicking on the button, it copies everything correctly but the selectize field does not contain inputs (i guess this is because they have the same id?) but I don't know how to instantiate another selectize instance on that object.



This is my code:



HTML:



<div class="row">
<div class="form-group col-12 mb-2 address-repeater">

<div data-repeater-list="stcity">
<div class="input-group mb-1" data-repeater-item>
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label for="companystreet"><?=lang("flow_company_street")?></label>
<input type="text" id="companystreet" class="form-control" placeholder="<?=lang("flow_company_streetname")?>" name="companystreet" required data-validation-required-message="<?=lang("flow_company_street_validation")?>">
<div class="help-block font-small-3"></div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label for="companystreetnumber"><?=lang("flow_company_nbr")?></label>
<input type="text" id="companystreetnumber" class="form-control" placeholder="<?=lang("flow_company_streetnbr")?>" name="companystreetnumber" required data-validation-required-message="<?=lang("flow_company_nbr_validation")?>">
<div class="help-block font-small-3"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="companycity"><?=lang("flow_company_city_or_commune")?></label>
<select id="companycity" class="companycity-select" name="companycity" autocomplete="new-password" required data-validation-required-message="<?=lang("flow_company_city_or_commune_validation")?>">
<option value="" selected><?=lang("flow_company_select_city_or_commune")?></option>
<?php
foreach ($citiesbe as $city) {
//Values are prefilled from javascript
$key = strtolower($city->name_nl) . "," . $city->zip_code;
echo "<option value="$key"> $city->name_nl ($city->zip_code)</option>";
}
?>
</select>
<div class="help-block font-small-3"></div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="companycountry"><?=lang("flow_company_country")?></label>
<select id="companycountry" class="companycountry-select" name="companycountry" autocomplete="new-password" disabled>
<option value="BE" selected><?=lang("flow_company_country_belgium")?></option>
</select>
</div>
</div>
</div>
</div>
</div>

<button type="button" data-repeater-create class="btn btn-primary">
<i class="ft-plus"></i> Add new address
</button>
</div>




Javascript:



// Custom Show / Hide Configurations
$('.address-repeater').repeater({
show: function () {
$(this).slideDown();
},
hide: function(remove) {
$(this).slideUp(remove);
}
});


Since the button is not the selectize element, I don't know how to assign it to the newly created element.










share|improve this question





























    1














    I have a form where the user can input multiple addresses, city, street+nbr and country.



    For this field to be repeated I use the jquery repeater library. For the city field I want to use a selectize input field.



    I am trying to repeat those 4 fields when clicking on the button, it copies everything correctly but the selectize field does not contain inputs (i guess this is because they have the same id?) but I don't know how to instantiate another selectize instance on that object.



    This is my code:



    HTML:



    <div class="row">
    <div class="form-group col-12 mb-2 address-repeater">

    <div data-repeater-list="stcity">
    <div class="input-group mb-1" data-repeater-item>
    <div class="row">
    <div class="col-md-8">
    <div class="form-group">
    <label for="companystreet"><?=lang("flow_company_street")?></label>
    <input type="text" id="companystreet" class="form-control" placeholder="<?=lang("flow_company_streetname")?>" name="companystreet" required data-validation-required-message="<?=lang("flow_company_street_validation")?>">
    <div class="help-block font-small-3"></div>
    </div>
    </div>
    <div class="col-md-4">
    <div class="form-group">
    <label for="companystreetnumber"><?=lang("flow_company_nbr")?></label>
    <input type="text" id="companystreetnumber" class="form-control" placeholder="<?=lang("flow_company_streetnbr")?>" name="companystreetnumber" required data-validation-required-message="<?=lang("flow_company_nbr_validation")?>">
    <div class="help-block font-small-3"></div>
    </div>
    </div>
    </div>
    <div class="row">
    <div class="col-md-6">
    <div class="form-group">
    <label for="companycity"><?=lang("flow_company_city_or_commune")?></label>
    <select id="companycity" class="companycity-select" name="companycity" autocomplete="new-password" required data-validation-required-message="<?=lang("flow_company_city_or_commune_validation")?>">
    <option value="" selected><?=lang("flow_company_select_city_or_commune")?></option>
    <?php
    foreach ($citiesbe as $city) {
    //Values are prefilled from javascript
    $key = strtolower($city->name_nl) . "," . $city->zip_code;
    echo "<option value="$key"> $city->name_nl ($city->zip_code)</option>";
    }
    ?>
    </select>
    <div class="help-block font-small-3"></div>
    </div>
    </div>
    <div class="col-md-6">
    <div class="form-group">
    <label for="companycountry"><?=lang("flow_company_country")?></label>
    <select id="companycountry" class="companycountry-select" name="companycountry" autocomplete="new-password" disabled>
    <option value="BE" selected><?=lang("flow_company_country_belgium")?></option>
    </select>
    </div>
    </div>
    </div>
    </div>
    </div>

    <button type="button" data-repeater-create class="btn btn-primary">
    <i class="ft-plus"></i> Add new address
    </button>
    </div>




    Javascript:



    // Custom Show / Hide Configurations
    $('.address-repeater').repeater({
    show: function () {
    $(this).slideDown();
    },
    hide: function(remove) {
    $(this).slideUp(remove);
    }
    });


    Since the button is not the selectize element, I don't know how to assign it to the newly created element.










    share|improve this question



























      1












      1








      1







      I have a form where the user can input multiple addresses, city, street+nbr and country.



      For this field to be repeated I use the jquery repeater library. For the city field I want to use a selectize input field.



      I am trying to repeat those 4 fields when clicking on the button, it copies everything correctly but the selectize field does not contain inputs (i guess this is because they have the same id?) but I don't know how to instantiate another selectize instance on that object.



      This is my code:



      HTML:



      <div class="row">
      <div class="form-group col-12 mb-2 address-repeater">

      <div data-repeater-list="stcity">
      <div class="input-group mb-1" data-repeater-item>
      <div class="row">
      <div class="col-md-8">
      <div class="form-group">
      <label for="companystreet"><?=lang("flow_company_street")?></label>
      <input type="text" id="companystreet" class="form-control" placeholder="<?=lang("flow_company_streetname")?>" name="companystreet" required data-validation-required-message="<?=lang("flow_company_street_validation")?>">
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      <div class="col-md-4">
      <div class="form-group">
      <label for="companystreetnumber"><?=lang("flow_company_nbr")?></label>
      <input type="text" id="companystreetnumber" class="form-control" placeholder="<?=lang("flow_company_streetnbr")?>" name="companystreetnumber" required data-validation-required-message="<?=lang("flow_company_nbr_validation")?>">
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      </div>
      <div class="row">
      <div class="col-md-6">
      <div class="form-group">
      <label for="companycity"><?=lang("flow_company_city_or_commune")?></label>
      <select id="companycity" class="companycity-select" name="companycity" autocomplete="new-password" required data-validation-required-message="<?=lang("flow_company_city_or_commune_validation")?>">
      <option value="" selected><?=lang("flow_company_select_city_or_commune")?></option>
      <?php
      foreach ($citiesbe as $city) {
      //Values are prefilled from javascript
      $key = strtolower($city->name_nl) . "," . $city->zip_code;
      echo "<option value="$key"> $city->name_nl ($city->zip_code)</option>";
      }
      ?>
      </select>
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      <div class="col-md-6">
      <div class="form-group">
      <label for="companycountry"><?=lang("flow_company_country")?></label>
      <select id="companycountry" class="companycountry-select" name="companycountry" autocomplete="new-password" disabled>
      <option value="BE" selected><?=lang("flow_company_country_belgium")?></option>
      </select>
      </div>
      </div>
      </div>
      </div>
      </div>

      <button type="button" data-repeater-create class="btn btn-primary">
      <i class="ft-plus"></i> Add new address
      </button>
      </div>




      Javascript:



      // Custom Show / Hide Configurations
      $('.address-repeater').repeater({
      show: function () {
      $(this).slideDown();
      },
      hide: function(remove) {
      $(this).slideUp(remove);
      }
      });


      Since the button is not the selectize element, I don't know how to assign it to the newly created element.










      share|improve this question















      I have a form where the user can input multiple addresses, city, street+nbr and country.



      For this field to be repeated I use the jquery repeater library. For the city field I want to use a selectize input field.



      I am trying to repeat those 4 fields when clicking on the button, it copies everything correctly but the selectize field does not contain inputs (i guess this is because they have the same id?) but I don't know how to instantiate another selectize instance on that object.



      This is my code:



      HTML:



      <div class="row">
      <div class="form-group col-12 mb-2 address-repeater">

      <div data-repeater-list="stcity">
      <div class="input-group mb-1" data-repeater-item>
      <div class="row">
      <div class="col-md-8">
      <div class="form-group">
      <label for="companystreet"><?=lang("flow_company_street")?></label>
      <input type="text" id="companystreet" class="form-control" placeholder="<?=lang("flow_company_streetname")?>" name="companystreet" required data-validation-required-message="<?=lang("flow_company_street_validation")?>">
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      <div class="col-md-4">
      <div class="form-group">
      <label for="companystreetnumber"><?=lang("flow_company_nbr")?></label>
      <input type="text" id="companystreetnumber" class="form-control" placeholder="<?=lang("flow_company_streetnbr")?>" name="companystreetnumber" required data-validation-required-message="<?=lang("flow_company_nbr_validation")?>">
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      </div>
      <div class="row">
      <div class="col-md-6">
      <div class="form-group">
      <label for="companycity"><?=lang("flow_company_city_or_commune")?></label>
      <select id="companycity" class="companycity-select" name="companycity" autocomplete="new-password" required data-validation-required-message="<?=lang("flow_company_city_or_commune_validation")?>">
      <option value="" selected><?=lang("flow_company_select_city_or_commune")?></option>
      <?php
      foreach ($citiesbe as $city) {
      //Values are prefilled from javascript
      $key = strtolower($city->name_nl) . "," . $city->zip_code;
      echo "<option value="$key"> $city->name_nl ($city->zip_code)</option>";
      }
      ?>
      </select>
      <div class="help-block font-small-3"></div>
      </div>
      </div>
      <div class="col-md-6">
      <div class="form-group">
      <label for="companycountry"><?=lang("flow_company_country")?></label>
      <select id="companycountry" class="companycountry-select" name="companycountry" autocomplete="new-password" disabled>
      <option value="BE" selected><?=lang("flow_company_country_belgium")?></option>
      </select>
      </div>
      </div>
      </div>
      </div>
      </div>

      <button type="button" data-repeater-create class="btn btn-primary">
      <i class="ft-plus"></i> Add new address
      </button>
      </div>




      Javascript:



      // Custom Show / Hide Configurations
      $('.address-repeater').repeater({
      show: function () {
      $(this).slideDown();
      },
      hide: function(remove) {
      $(this).slideUp(remove);
      }
      });


      Since the button is not the selectize element, I don't know how to assign it to the newly created element.







      javascript jquery repeater selectize.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 14:50

























      asked Nov 21 '18 at 13:02









      Dennis

      5491720




      5491720
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412645%2frepeat-selectize-select-field%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412645%2frepeat-selectize-select-field%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'