When using this, one is required to press add. It'd be nice instead to have it more as an optional part of workflow.

Could simply add a event to un-submit that goes and chucks the tags to the new area.

(There could even be an option that piggy backs onto the comma seperation setting that chucks the tags up there without even using the add button in general).

Comments

nagiek’s picture

Seconded.

mattwmc’s picture

If the first post is describing how it's done with Tumblr or YouTube, I'm all for it.

Otherwise, I gotta pass.

Thanks.

attila.fekete’s picture

Status: Active » Needs review
StatusFileSize
new3.43 KB

Hi! Try this patch. Pressing 'Add' is optional. (Also includes fix for http://drupal.org/node/1257268).

attila.fekete’s picture

Patch in #3 not working, fixed.

Georgique’s picture

Title: Process the information in the textbox when user presses submits as valid tags to add » Several problems on element validation: retheming already added tags, processing tags in the textfield
Category: feature » bug
StatusFileSize
new3.68 KB

Let's use this issue for fixing both problems (I've marked http://drupal.org/node/1257268 as a duplicate).
Attaching improved #4 patch:
1) JS code a bit improved to be more quick
2) Validation fixed for cases when active tags widget was moved into some container (fieldset, etc.)
Please, review.

Georgique’s picture

StatusFileSize
new3.75 KB

Improved retrieving values from $form_state['values'].

Georgique’s picture

StatusFileSize
new4.24 KB

Removed "dirty" js code which were adding tags on submit, improved retrieving values from $form_state

k.dani’s picture

Status: Needs review » Needs work

I would like to use the Active Tags with Profile 2. I tried all of the patches above, but I always got errors during the validation:

Notice: Undefined index: field_term_reference in active_tags_taxonomy_autocomplete_validate()
Warning: Invalid argument supplied for foreach() in taxonomy_field_presave()
k.dani’s picture

Status: Needs work » Needs review
StatusFileSize
new4.32 KB

I created a new patch based on Georgique's latest patch. Now it works properly on profiles as well.

Georgique’s picture

StatusFileSize
new4.22 KB

@k.dani Yes, your patch is better, but was not working on my project, so I fixed and improved it. Please, review and test

loze’s picture

the patch in #10 works for me. Thanks!

pfrenssen’s picture

Issue summary: View changes
StatusFileSize
new3.1 KB
new2.81 KB
new2.82 KB

I'm trying to make sense of the history of these patches. I attached the missing interdiffs starting from patch #7. It seems that the patch in #9 was a regression in terms of comment quality. This has been fixed again in #10.

pfrenssen’s picture

Review:

  • It is very unfortunate that this issue has been polluted and is now trying to solve three problems at the same time. It would be better to split this up into three different issues:
    1. Allow to add tags on submit, without having to click "Add" first (original issue)
    2. Make sure the javascript is loaded after form validation fails.
    3. Make sure previously entered tags still show up after form validation fails.
  • When a tag that contains commas is entered and "Add" is clicked, this is added as is (with the commas visible inside the tag). However, when "Add" is not clicked, the tag is split up at the commas into separate tags when the form is submitted. This should work in an identical way, either commas are used to split up the tags, or they are retained.
  • All comments should end in a period.
  • The code seems to have been thrown together rather haphazardly, with different flags and arrays in use, and variables that are initialized outside of the if switches in which they are used. This is quite hard to follow.
  • Depending on whether or not the tag field is filled in, taxonomy_autocomplete_validate() may be executed twice.
pfrenssen’s picture

Status: Needs review » Needs work
  1. +++ b/active_tags.js
    @@ -62,9 +58,12 @@ activeTags.addTerm = function (context, term) {
    +    var terms = term.split(',');
         var termDiv = $(context);
         var termList = termDiv.parent().find('.at-term-list');
    -    termList.append(Drupal.theme('activeTagsTermRemove', term));
    +    for (var i = 0; i < terms.length; i++) {
    +      termList.append(Drupal.theme('activeTagsTermRemove', terms[i]));
    +    }
         // Attach behaviors to new DOM content.
    

    This doesn't take the widget settings regarding splitting on comma into account.

  2. +++ b/active_tags.module
    @@ -83,8 +85,50 @@ function active_tags_field_widget_error($element, $error, $form, &$form_state) {
    +  // Try to check if we left term(s) in the entry field
    +  if (!empty($element['term_entry']['#value']) || ($element['terms']['#default_value'] != $element['terms']['#value'])) {
    +    $entry_field_not_empty = TRUE;
    

    Use $form_state['values'] to retrieve the values, rather than relying on the form values.

  3. +++ b/active_tags.module
    @@ -83,8 +85,50 @@ function active_tags_field_widget_error($element, $error, $form, &$form_state) {
    +    if (!empty($element['term_entry']['#value'])) {
    +      $element['terms']['#value'] .= ', ' . $element['term_entry']['#value'];
    

    2 lines higher it is already determined that this is not empty.

  4. +++ b/active_tags.module
    @@ -83,8 +85,50 @@ function active_tags_field_widget_error($element, $error, $form, &$form_state) {
    +    drupal_array_set_nested_value($form_state['complete form'], $parents, '');
    +  }
    

    Don't set values in $form_state['complete form'], put them in $form_state['values'] instead.

  5. +++ b/active_tags.module
    @@ -83,8 +85,50 @@ function active_tags_field_widget_error($element, $error, $form, &$form_state) {
    +    taxonomy_autocomplete_validate($element, $form_state);
    +  }
    

    Is it really needed to call this validation function twice? It has already been called before.

  6. +++ b/active_tags.module
    @@ -83,8 +85,50 @@ function active_tags_field_widget_error($element, $error, $form, &$form_state) {
    +    drupal_array_set_nested_value($form_state['complete form'], $parents, $value);
    +  }
    

    Don't set values in $form_state['complete form'], put them in $form_state['values'] instead.

pfrenssen’s picture

StatusFileSize
new4.42 KB
new3.5 KB

I addressed my remarks. I was mistaken about using $form_state['values'], apparently when using element validation you have to use $form_state['complete form'] instead. Also the splitting on commas is not done in js but in the validate handler by wrapping the tag with quotes.

This is a simplified version of the patch that retains full functionality, and also supports the 'csv' option.

While testing the patch I was encountering some notices, but these are due to a core issue: #1525176: Using array_diff_assoc() for multilevel arrays in DrupalDefaultEntityController->cacheGet().

pfrenssen’s picture

Status: Needs work » Needs review

Back to needs review.

pfrenssen’s picture

StatusFileSize
new5.12 KB
new999 bytes

Updated the theme function, the tags are no longer unecessarily presaved on form validation, so their tids may or may not be present.

isolate’s picture

Status: Needs review » Reviewed & tested by the community

#17 looks good.

DeFr’s picture

Status: Reviewed & tested by the community » Needs work

#17 doesn't look all that good on the error validation part.

Re-theming should not happen in a validate handler. Instead, there should be a '#pre_render' callback handling the theming all the time, making it all more consistent.

I really think those 3 issues should be split instead of meshed into one, but, given the state we're in, maybe we should just try to get things rolling. (Must say there's a bunch of code that makes it really tempting to clean it all up though)

DeFr’s picture

StatusFileSize
new5.39 KB
new2.83 KB

This is what it'd look like with the #pre_render call.

Haven't really looked at the rest of the patch yet, but there's some other things that seems problematic ; at least the terms = term.split(','); is badly breaking the tag additions for terms that includes a , in them and are selected through the autocomplete functionnality. In that case you get a 'Foo, Bar' in the textfield, but clicking the Add button leads to the creation of two terms. To be honest, I don't understand at all why that was added here: tag splitting on commas is already handled in addTerms if needed, addTerm always get a single term. I'd completely remove that change.

Anonymous’s picture

The patch in #20 solved my problems (primarily, the widget breaking and losing newly added values when there was a validation error).

michelle’s picture

StatusFileSize
new5.4 KB

The patch in #20 had one hunk fail because the line being replaced has had a check_plain added to it in the latest code. I've rerolled the patch against current 7.x-2.x.

I've left this at "needs work" because that's where it was with the previous patch and all I did was reroll it so it applies. I didn't address any of the issues noted.

mahyarsbt’s picture

Assigned: Unassigned » mahyarsbt
Status: Needs work » Fixed

Thank you for your continued interest in the Active Tags module.

We are excited to announce that the issue you raised has been addressed in the revitalized Active Tags version 1.0.0. This update supports Drupal 9, 10, and 11 and brings a modern interface along with a range of new features to enhance your Drupal tagging experience, including:

  • Enhanced Tag Styling: Enjoy a modern and visually appealing interface for entity reference fields.
  • Dynamic Tag Creation: Flexibly enable or disable tag creation based on your Drupal settings.
  • Support for User Avatars: Display user avatars in tags when using the User entity autocomplete.
  • Efficient Tag Management: Organize tags effortlessly with drag-and-sort functionality, duplicate protection, and multiple selection support.
  • Entity ID Display: Optionally display the entity ID alongside each tag for added clarity.
  • Integration with Key Modules: Seamlessly integrate with Token, Webform, Facets, and Better Exposed Filters for enhanced filtering and autocomplete functionality.

This is just a glimpse of the new capabilities. We encourage you to explore these new features by downloading the latest version. For a full list of features and more details, please visit the Active Tags project page.

mahyarsbt’s picture

Status: Fixed » Closed (fixed)

With the release of Active Tags 1.0.0, we believe this issue has been fully resolved. We invite you to explore the latest version and share any feedback you have.

Thank you for your continued support and contributions to the Drupal community. Together, we can keep improving Active Tags!


Visit the Active Tags project page to stay updated and provide feedback.