Sha256: ed9c9a3bf6fe11f77b9d25da8164c6aef5840235cae8b1767f8b0241c2e0b02f
Contents?: true
Size: 1.58 KB
Versions: 2
Compression:
Stored size: 1.58 KB
Contents
///- - - - - - - - - - - - - - - - - - - - /// FORM ITEM ///- - - - - - - - - - - - - - - - - - - - class FormItemRepeater { constructor() { this.target = '.form-item--repeater-section' } isSet() { if ( $( this.target ).length > 0 ) { return true } else { return false } } setEvents() { $(document).on('click', this.target + '--add-new', addNewItem ) $(document).on('click', '.form-item--remove-item-with-js', function( event ) { // Stop default behaviour event.preventDefault() $( this ).parent( this.target ).remove() }) $(document).on('click', '.form-item--delete-repeater-item', function( event ) { // Stop default behaviour event.preventDefault() $.ajax({ url: $( this ).attr('href'), data: { id: $( this ).data('id'), isAjax: true }, method: "DELETE" }).done( ()=>{ $( this ).parent('li').remove() }) }) } } export let _FormItemRepeater = new FormItemRepeater() ///- - - - - - - - - - - - - - - - - - - - /// COMPONENT HELPER FUNCTIONS ///- - - - - - - - - - - - - - - - - - - - function addNewItem( event ) { // Stop default behaviour event.preventDefault() // Get the child to clone let id = $( event.target ).data( 'id' ) let $list = $('#form-item--repeater-setting-' + id ) let url = $( event.target ).data( 'url' ) $.post( url, { repeater_setting_id: id }, function( data ) { let parts = data.split('<!-- SPLIT -->') let newRepeater = parts[1] $list.append( newRepeater ) var editor_id = $list.find('textarea').last('textarea').attr('id') tinyMCE.EditorManager.execCommand('mceAddEditor',true, editor_id); }) }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
binda-0.0.3 | app/assets/javascripts/binda/components/form_item_repeater.js |
binda-0.0.2 | app/assets/javascripts/binda/components/form_item_repeater.js |