[[*id:is=`101` //NewsPublisers id
:then=`[[!tagLister? &tv=`articlestags` &tpl=`npTagTpl` &parents=`201` //the actual blog
&limit=`100`]]`]]
<div id="np-[[+npx.fieldName]]-container" class="np-text"> [[+np.error_[[+npx.fieldName]]]] <label class="fieldlabel" for="np-[[+npx.fieldName]]" [[+npx.readonly]] title="[[+npx.help]]">[[+npx.caption]]: </label> <input name="[[+npx.fieldName]]" class="text" id="np-[[+npx.fieldName]]" type="text" value="[[+np.[[+npx.fieldName]]]]" maxlength="[[+npx.maxlength]]" /> </div> <script> $(function() { var [[+npx.fieldName]]Tags = [ [[!tagLister? &tv=`[[+npx.fieldName]]` &tpl=`npTagTplJSON` &parents=`213` &sortBy=`tag` &limit=`0` &outputSeparator=`,`]] ]; function split( val ) { return val.split( /,\s*/ ); } function extractLast( term ) { return split( term ).pop(); } $( "#np-[[+npx.fieldName]]" ) // don't navigate away from the field on tab when selecting an item .bind( "keydown", function( event ) { if ( event.keyCode === $.ui.keyCode.TAB && $( this ).data( "ui-autocomplete" ).menu.active ) { event.preventDefault(); } }) .autocomplete({ minLength: 0, source: function( request, response ) { // delegate back to autocomplete, but extract the last term response( $.ui.autocomplete.filter( [[+npx.fieldName]]Tags, extractLast( request.term ) ) ); }, focus: function() { // prevent value inserted on focus return false; }, select: function( event, ui ) { var terms = split( this.value ); // remove the current input terms.pop(); // add the selected item terms.push( ui.item.value ); // add placeholder to get the comma-and-space at the end terms.push( "" ); this.value = terms.join( ", " ); return false; } }); }); </script>
Banana, apple, mango,
if (empty($tag)) { continue; else { tag = trim(', ') tag. }
$fields['tv' . $tv->get('id')] = $_POST[$name];
if ($name == 'TagTV') { // or whatever the TV's name is $tags = explode(',', $_POST[$name]); foreach ($tags as $tag) { $tag = trim($tag); if ($empty(tag)) { $finalTags[] = $tag; } $_POST[$name] = implode(',', $finalTags); } }
$('form').submit(function(e) { $('.ui-autocomplete-input').each(function() { var pH = $.trim($(this).val()); var pHn = pH.replace(/,\s*$/, ''); $(this).val(pHn); }); });