Sha256: a21aa733235380dfdbb2df5530a715c1c069282358e4af906872808de870a8b8
Contents?: true
Size: 1.73 KB
Versions: 2
Compression:
Stored size: 1.73 KB
Contents
/** * FORM ITEM CHOICE */ import { _FormItemEditor } from "./form_item_editor"; class FieldSettingChoices { constructor() { this.target = ".field-setting-choices--choice"; } isSet() { if ($(this.target).length > 0) { return true; } else { return false; } } setEvents() { $(document).on( "click", ".field-setting-choices--add-choice", addChoice ); $(document).on( "click", ".field-setting-choices--delete-choice", deleteChoice ); $(document).on( "click", ".field-setting-choices--js-delete-choice", function(event) { event.preventDefault(); $(this) .closest(".field-setting-choices--choice") .remove(); // Update form item editor size _FormItemEditor.resize(); } ); } } export let _FieldSettingChoices = new FieldSettingChoices(); /** * HELPER FUNCTIONS */ function addChoice(event) { event.preventDefault(); // Clone the new choice field var choices_id = $(this).data("choices-id"); var choices = $(`#${choices_id}`); var newchoice = choices.find(".field-setting-choices--new-choice"); var clone = newchoice .clone() .removeClass("field-setting-choices--new-choice") .toggle(); clone.find(".field-setting-choices--toggle-choice").toggle(); // Append the clone right after choices.prepend(clone); // Update form item editor size _FormItemEditor.resize(); } function deleteChoice(event) { event.preventDefault(); var choice = $(this).closest(".field-setting-choices--choice"); var destination = $(this).attr("href"); var self = this; $.ajax({ url: destination, type: "DELETE" }).done(function() { choice.remove(); // Update form item editor size _FormItemEditor.resize(); }).fail(function(data){ alert(data.responseJSON.errors); }); }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
binda-0.1.5 | app/assets/javascripts/binda/components/field_setting_choices.js |
binda-0.1.4 | app/assets/javascripts/binda/components/field_setting_choices.js |