I'm trying to make dynamically created checkboxes on a plone temaplate, using tal-repeat
. Check the below code for details.
<div tal:define="global pessoa python:view.dados_pessoa()" class="drop-element"></div>
<div class="row m-t-10" tal:repeat="telefone python: pessoa.get('telefones', [])">
<input type="hidden" class="idTelefone" name="telefones.id" value="${python: telefone.get('id', '')}" />
<div class="col s3 grey-text text-darken-1">
<input class="grey-text text-darken-1 tipoTelefone" type="text" name="telefones.tipo" value="${python: telefone.get('tipo', '').capitalize()}" autoComplete="off" readonly />
</div>
<div class="col s5">
<input class="grey-text text-darken-1 numeroTelefone" type="text" name="telefones.numero" value="${python: '(%s) %d' % (telefone.get('ddd', ''), telefone.get('numero', ''))}" autoComplete="false" readonly/>
</div>
<div class="col s2">
<input type="checkbox" id="${python: telefone.get('id', '')}" name="telefones.sms" ${python: 'checked' if telefone.get('sms', '') else ''}>
<label for="${python: telefone.get('id', '')}" class="active fix-label" style="top: 25px !important">SMS</label>
</div>
<div class="input-field m-t-10 col s2">
<button type="button" class="sp_btn right red m-t-05 btn-remover-telefone">Remover</button>
</div>
</div>
Putting it simple, pessoa['telefones']
is a list, that can come with 0 or more dictionaries.
The point here is at the lines:
<input type="checkbox" id="${python: telefone.get('id', '')}" name="telefones.sms" ${python: 'checked' if telefone.get('sms', '') else ''}>
<label for="${python: telefone.get('id', '')}" class="active fix-label" style="top: 25px !important">SMS</label>
As my plone site uses materialize, i need to connect a label to a checkbox via id, else it wont show. Sounds like it will work, since each index on telefone
have a unique id. The problem is that when that renders, the ID property is rendered as a string of the TALES expression instead of the expression result, like that:
<input type="checkbox" id="${python: telefone.get('id', '')}" name="telefones.sms">
<label for="2138518" class="active fix-label" style="top: 25px !important">SMS</label>
Why? how can i get around it? Searched on everything i could, and can't find a solution.
what Plone version do you use? I ealier version expressions like ${} didn't exist. What should work al time is somehing like this:
<input type="checkbox" tal:attributes="id python: telefone.get('id', '')"> name="telefones.sms">
hope that will help you, cheers Maik