Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

'schema': settings: options must be an array

'schema': settings: options must be an array

lokki54
Shopify Partner
55 0 15

How to add dynamic options for a selection to the theme app blocks?

The metafields are perfect for this but Shopify Cli does not allow to publish of such code

 

 

{
      "type": "radio",
      "id": "logo_aligment",
      "label": "Logo alignment",
      "options": "{{ app.metafields.myapp.some_select.value }}"
    }
  ]
}
{% endschema %}

 

 

 

Replies 2 (2)

EcomGraduates
Shopify Partner
781 68 112

ello there 

 

To add dynamic options for a selection to the theme app blocks, you can use JavaScript to fetch the data from the metafields and populate the options for the selection field.

First, add the selection field to your schema as follows:

 

{ "type": "select", "id": "my_select", "label": "My Select", "options": [] }

 

Then, in your JavaScript code, fetch the dynamic options from the metafields and populate them in the selection field as follows:

 

const mySelectField = document.querySelector('#my_select');
const options = "{{ app.metafields.myapp.some_select.value }}";
const optionsArray = options.split(',');

optionsArray.forEach(option => {
  const newOption = document.createElement('option');
  newOption.value = option;
  newOption.text = option;
  mySelectField.add(newOption);
});

 


 If this fixed your issue, likes and accepting as a solution are highly appreciated
|  Build an online presence with our custom-built Shopify Theme: EcomifyTheme
|  Check out our reviews: Trustpilot Reviews
|  We are Shopify Partners: EcomGraduates Shopify Partner



lokki54
Shopify Partner
55 0 15

Thank you for your reply but Shopify CLI does not allow to publish of such code

[blocks/conditional-app-block.liquid] Invalid tag 'schema': settings: with  id="my_select" options can't be empty

 

Looks like Shopify dev team do everything to cut flexibility and force to tell clients change platform to another.