سؤال

I have the following code in my forms.ini file, that is not working (form rendered is still using the default DtDd decorator).

incident.elements.ticket_number.type = "text"
incident.elements.ticket_number.options.label = "Ticket Number"
incident.elements.ticket_number.options.required = true
incident.elements.ticket_number.decorators.elements.decorator = "ViewHelper"
incident.elements.ticket_number.decorators.list_item.decorator = "HtmlTag"
incident.elements.ticket_number.decorators.list_item.options.tag = "li"
incident.elements.ticket_number.decorators.label.decorator = "Label"

Showing output:

<dt id="ticket_number-label">
    <label for="ticket_number" class="required">Ticket Number</label>
</dt>
<dd id="ticket_number-element">
    <input type="text" name="ticket_number" id="ticket_number" value="">
</dd>

However I want it to show:

<li>
    <label for=...>Ticket Number</label>
    <input type="text" name="ticket_number" id="ticket_number" value="">
</li>

what am I doing wrong here?

هل كانت مفيدة؟

المحلول

I believe the decorators for the element need to be added as options as well.

See if the following works for you:

incident.elements.ticket_number.type = "text"
incident.elements.ticket_number.options.label = "Ticket Number"
incident.elements.ticket_number.options.required = true
incident.elements.ticket_number.options.decorators.viewhelper.decorator = "ViewHelper"
incident.elements.ticket_number.options.decorators.label.decorator = "Label"
incident.elements.ticket_number.options.decorators.errors.decorator = "Errors"
incident.elements.ticket_number.options.decorators.description.decorator = "Description"
incident.elements.ticket_number.options.decorators.htmltag.decorator = "HtmlTag"
incident.elements.ticket_number.options.decorators.htmltag.options.tag = "li"

Note that I also changed the order of the decorators slightly so that the <label> tag would also be wrapped in the <li> tag. If the label is after the HtmlTag I found it would prepend the input, but was not wrapped in <li>

You will also have to specify the decorators for each form element, otherwise they will use the default form decorators. You could set the above spec to be your default decorator, but then you will also need special decorators for buttons/submit and file inputs.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top