Home>Support>value_method on repeater

value_method on repeater

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. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 6 months, 17 days ago Alex S
    Hi, I Work Here

    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. 6 months, 17 days ago Michael Dubois

    Top, it’s work

    Thank’s Alex

  3. 6 months, 17 days ago Alex S
    Hi, I Work Here

    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.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More