alexgorbatchev / jquery-textext

A super awesome, customizable text input supporting tags, autocomplete, ajax and other goodness in a crazy cool a-la cart way.
http://textextjs.com
MIT License
1.27k stars 201 forks source link

Use of textext with ZF2 form #136

Open rubenve opened 11 years ago

rubenve commented 11 years ago

I'm using TextExt in a ZF2 application to allow the user to tag news items. I'm using the ajax, tags and autocomplete plugins:

  // Tags autocomplete
  var textext = $("#newsitem\\[tags\\]").textext({
        plugins : 'tags autocomplete filter ajax',
        ajax : {
            url : '/news/get-list-of-tags',
            dataType : 'json',
            cacheResults : true
        }
    });

This all works fine and dandy except when the form doesn't validate and Zend Form automatically sets the values of the form elements to whatever was posted. In case of the tags element this means it populates it with something like ["tag1","tag2"] Is there a way I can force textext to parse the value of the element to make it show the value as tags? I think I would need to call the itemManager stringToItem method correct? Any help would be greatly appreciated.

rubenve commented 11 years ago

I don't know if this place is still alive, but if anyone ever needs something similar this is how I fixed it:

        // Reset existing tags from tags textfield value if any
    if ($("#newsitem\\[tags\\]").val().length > 0)
    {
        try
        {
            var tags = $.parseJSON($("#newsitem\\[tags\\]").val());
            $("#newsitem\\[tags\\]").val('');
            $("#newsitem\\[tags\\]").textext()[0].tags().addTags(tags);
        }
        catch (e) {}
    }