Fail for muti select values

Created on 6 March 2024, 4 months ago
Updated 20 March 2024, 3 months ago

Problem/Motivation

If we have form with mutit value so selector in js i base on id but without delta
exemple i have select html
<select aria-label="demandeur qualite" data-drupal-selector="edit-field-demandeurqualite-select" id="edit-field-demandeurqualite-select--2" name="field_demandeurqualite[select]" class="form-select select-or-other-initialized"
and other html
<div class="js-form-item form-item js-form-type-textfield form-type-textfield js-form-item-field-demandeurqualite-other form-item-field-demandeurqualite-other"
but in js it takes id to get field name. Id field will add --delta

(function ($) {
  'use strict';
  function select_or_other_check_and_show($select, speed) {
    var $select_id = $select.attr('id').replace('select', 'other').replace('edit-field-', '')
    var $other = $(`.js-form-item-field-${$select_id}`)

Proposed resolution

I suggest to change selector $select_id and $other to

    let $select_id = $select.attr('data-drupal-selector').replace('edit-field-', '').replace('-select', '-other');
    let $other = $select.closest('.form-type-select-or-other-select').find(`.js-form-item-field-${$select_id}`);

or

    let $select_id = $select.attr('id').split('-select')[0].replace('edit-field-', '');
    let $other = $select.closest('.form-type-select-or-other-select').find(`.js-form-item-field-${$select_id}-other`);

It is generic and it works in all cases

πŸ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡«πŸ‡·France lazzyvn paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @lazzyvn
  • Status changed to Closed: duplicate 3 months ago
  • πŸ‡§πŸ‡ͺBelgium baikho Antwerp, BE
  • Status changed to Active 3 months ago
  • πŸ‡«πŸ‡·France lazzyvn paris

    @baikho
    Why did you close this ticket? it's very different. please read carefully
    I want to base the logic on $select.attr('data-drupal-selector'), actually the ID based origin is not correct for many values. field with multi-valued id adds ID--DELTA but data-drupal selector does not.

  • πŸ‡«πŸ‡·France lazzyvn paris

    Fixed support drupal 11

Production build 0.69.0 2024