Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Metronic 8: Form Repeater


How to call a function after success on form repeater?
I need to make a new instance of tagify on the element being created by the form repeater.


$("#form_img_location").repeater({
initEmpty: false,

defaultValues: {
"text-input": "foo"
},

show: function () {
$(this).slideDown();
},

hide: function (deleteElement) {
$(this).slideUp(deleteElement);
}
});


TAGIFY:

var tagifyFields = document.getElementsByClassName("input-tagify");
var tagifyFieldsList = Array.prototype.slice.call(tagifyFields);
if (tagifyFieldsList.length) {
tagifyFieldsList.forEach(createTagifyFields);
}

function createTagifyFields(input) {
$.ajax({
url: "/MyController/Taglist",
method: "GET",
data: {},
success: function (response) {
// var input = document.querySelector("input[name="input-custom-dropdown"]"),
// init Tagify script on the above inputs
var tagify = new Tagify(input, {
whitelist: response,
maxTags: 10,
dropdown: {
maxItems: 20, // <- mixumum allowed rendered suggestions
classname: "tags-look", // <- custom classname for this dropdown, so it could be targeted
enabled: 0, // <- show suggestions on focus
closeOnSelect: false // <- do not hide the suggestions dropdown once an item has been selected
},
originalInputValueFormat: valuesArr => valuesArr.map(item => item.value).join(",")
})




var tagify = new Tagify(input, {
whitelist: response,
maxTags: 10,
dropdown: {
maxItems: 20, // <- mixumum allowed rendered suggestions
classname: "tags-look", // <- custom classname for this dropdown, so it could be targeted
enabled: 0, // <- show suggestions on focus
closeOnSelect: false // <- do not hide the suggestions dropdown once an item has been selected
}
})

new Tagify(input);
}
});
}





<div id="form_img_location">
<div class="form-group">
<div data-repeater-list="form_img_location">
<div data-repeater-item>
<div class="form-group row ">

<div class="col-md-3 input-group-sm">
<label class="form-label">Tags:</label>
<input class="form-control form-control-sm tags-look input-tagify tags">
</div>
<div class="col-md-1">
<a href="javascript:;%22%20data-repeater-delete%20class=%22btn%20btn-sm%20btn-light-danger%20mt-3%20mt-md-8" target="_blank">
Delete
</a>
</div>
</div>
</div>
</div>
</div>
<div class="form-group mt-5">
<a href="javascript:;%22%20data-repeater-create%20class=%22btn%20btn-sm%20%20btn-secondary" target="_blank">
<i class="ki-duotone ki-plus fs-3"></i>
Add Row
</a>
</div>
</div>


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi,

Sorry for the late reply. Could you please clarify what you mean by success?

Please check the jQuery repeater plugin docs here.

Regards.



I mean after creating or repeating the form. inside that form i have input element which needs the new instance of tagify.

I already check the documentation but I cant see where can I put the code to call my function to create instance of tagify after the successful creation of the form.



Hi,

You can refer to the original docs of the plugin here to run your code in show callback after a new item is added:


// (Optional)
// "show" is called just after an item is added. The item is hidden
// at this point. If a show callback is not given the item will
// have $(this).show() called on it.
show: function () {
// run your code after a new item is added
},


Regards.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(