Reputation: 17
I have a content type which has 5 fields and one of them is a UI extension which generates two text fields from HTML. I'm not able to access the second text field inside the UI extension field.
I'm using JavaScript to access the two text fields inside the UI extension field. However, I'm only able to access the first field. How do I also retrieve and manipulate the second text field?
<form method="post" id="webAddressForm">
<div class="table form-fields">
<div class="row name">
<div class="label">Web address:</div>
<div class="input full"><input type="text" name="web-address" id="webAddress" placeholder="http://google.com"/></div>
</div>
<br>
<div class="row name">
<div class="label">Text to display:</div>
<div class="input full"><input type="text" name="website-name" id="websiteName" placeholder="Google"/></div>
<br>
</div>
</div>
</form>
JS being used so far to get the value of the field.
console.log(api.field.getValue()) // this only returns the value from the first text field.
I am trying to access both webAddress and websiteName text fields.
Upvotes: 1
Views: 537
Reputation: 3879
If you want to store multiple values in one field you have to choose the field type JSON object
.
By default, Contentful supports several different types for one field but all of them are single values. By choosing JSON as a type for your field (and your UI extension) you can work around this and store the data you need because you have complete control over the JSON structure.
Hope that helps. :).
Here you can find an example I wrote ages ago modelling tabular data in a single field.
Upvotes: 0