T
T
Tutucu2015-11-04 14:34:10
Drupal
Tutucu, 2015-11-04 14:34:10

jquery and adding new fields. How to put a handler on dynamically created fields?

I created my field (2 hidden and 1 textfield), assigned autocomplete to them with my widgets (widget factory) - for the first field everything goes well, but when you add a new field (set an unlimited number of fields in the settings) and add text to the new field the handler starts changing the data in all previous fields, tried to apply once() did not help.
Here are the places where selectors are used:

Drupal.behaviors.jqe = {
  attach: function (context, settings) {
 
  $('.fields-nazvaniye').once('demo-fields', function () {
        $(".fields-nazvaniye", context).makeJqeAutocomplete();
      });
  }// attach
};

In the .makeJqeAutocomplete();
select: function(event, ui) {
        // nid скрытому полю.
        $('#fields_href').val(ui.item ? ui.item.value.href : 0);
        // текст - в поле.
        $input.val(ui.item ? ui.item.value.title : this.value);
    $('#fields_class').val(ui.item ? ui.item.value.class : '');
        return false;
      }
    });
    return this;
  };


I searched on the Internet and did not find similar problems. Please help, it's been 5 days I can't decide. If necessary, I can give the entire code of the widget.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afi13, 2015-11-04
@Tutucu

I would venture to suggest that you have the same wrapper over all fields with the fields-nazvaniye class, so it works for all fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question