Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active November 23, 2020 23:57
Show Gist options
  • Save obiPlabon/15c8ed8444b952dc7bf398d0219219c7 to your computer and use it in GitHub Desktop.
Save obiPlabon/15c8ed8444b952dc7bf398d0219219c7 to your computer and use it in GitHub Desktop.
Elementor snippet to get the option name from a repeater select field by passing option key
<?php
'title_field' => "<#
// This snippet doesn't ensure that it won't throw any error if there's no row/repeater item
// Make sure to check that
// First get the repeater control
var repeaterControl = elementor.getPanelView().getCurrentPageView().children.find(function(view) {
return view.model.get('name') === 'staffs';
}),
// Get the first row from repeater
firstRow = repeaterControl.children.findByIndex(0),
// Get the title
// Use staff_id instead of id, id is used in elementor internally
// and may cause unexpected issues
title = firstRow.model.controls.staff_id.options[ staff_id ];
print(title);
#>"
<?php
'title_field' => "<#
// This snippet doesn't ensure that it won't throw any error if there's no row/repeater item
// Make sure to check that
// First get the repeater control
var repeaterControl = elementor.getPanelView().getCurrentPageView().children.find(function(view) {
return view.model.get('name') === 'repeater_control_id_goes_here';
}),
// Get the first row from repeater
firstRow = repeaterControl.children.findByIndex(0),
// Get the title by passing the
// ** Select control id goes here without the curly braces
title = firstRow.model.controls.{**}.options[{**}];
print(title);
#>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment