value_method on repeater

1 year ago · Last reply by Alex S 1 year ago

Hello,

in a repeater, I have a select field.
When I indicate ‘val’ in value_method of the “item_label”, the value of selected option is writing correctly. But I want it’s write the text of selected option.
So for this I indicate ‘text’ in value_method but when I do this I have text of all option that its’ write.

Could you help me please ?

Thanks

$form['brands'] = [
    'type' => 'repeater',
    'label'     => __( 'Brands' , $this->domainTrad ),
    'item_name' => __( 'Brand', $this->domainTrad ),
    'item_label' => [
        'selector'     => "[id*='brand']",
        'update_event' => 'change',
        'value_method' => 'text'
    ],
    'fields'    => [
        'brand' => [
            'type' => 'select',
            'label' =>  'Choose a Brand',
            'options' => [
                '1' => 'test 1',
                '2' => 'test 2',
                '3' => 'test 3',
                '4' => 'test 4',
            ]
        ]
    ]
];

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

3
  1. Alex S Staff 1 year, 1 month ago

    Hi Michael,

    Thanks for getting in touch. You can return the value by specifically targeting the selected option. Change:

    'selector'     => "[id*='brand']",

    To:

    'selector'     => "[id*='brand'] option:selected",

    Kind regards,
    Alex

  2. Michael Dubois 1 year, 1 month ago

    Top, it’s work

    Thank’s Alex

  3. Alex S Staff 1 year, 1 month ago

    Hi Michael,

    It’s great to hear that helped! :)
    Please feel free to open a new thread if anything else comes up.

    Kind regards,
    Alex

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread