We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Condition in text field

Hello! I need to add a condition in the text field.

I want to get something like:

{{ text_field('test', 'class': 'input w-full border', 'value': contract.totalPrice|default(""), 'required': (contract.id is not empty) ? false : true) }}

but it does not work. there is some solution?

edited Nov '20

Maybe determine that before the field:

{% set required = true %}
{% if contract.id is not empty %}
    {% set required = false %}
{% endif %}

{{ text_field('test', 'class': 'input w-full border', 'value': contract.totalPrice|default(""), 'required': required) }}

Or, if you don't mind mixing in a little raw PHP code:

<?php $required = !isset($contract.id); ?>

{{ text_field('test', 'class': 'input w-full border', 'value': contract.totalPrice|default(""), 'required': required) }}


4.3k

thanks! I understand that you can do just that. but I think we can write the condition inside text_field.

Maybe determine that before the field:

{% set required = true %}
{% if contract.id is not empty %}
  {% set required = false %}
{% endif %}

{{ text_field('test', 'class': 'input w-full border', 'value': contract.totalPrice|default(""), 'required': required) }}

Or, if you don't mind mixing in a little raw PHP code:

<?php $required = !isset($contract.id); ?>

{{ text_field('test', 'class': 'input w-full border', 'value': contract.totalPrice|default(""), 'required': required) }}
edited Dec '20

Try:

if([txtName.text length] == 0 || [txtName.text isEqualToString:@""]) { //TalkToWendys } Test length to 0 or compare string to a blank string.