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

Can we set Glyphicon-icon to variable in form itself?

At the time of rendering a date field i want to display glyphicon-calender icon....for this i tried following...but i am getting glyphicon-icon at the bottom of the field....how to rectify this...whether we can set this in form itself or how can we do this in volt ? Please Help..!!!

                            {% for element in form %}
                                {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %}
                                    {{ element }}
                                {% elseif element.getName() == "txn_date" %}
                                    <div class="form-group" >
                                        {{ element.label() }}
                                        {{ element.render(['class': 'form-control']) }}
                                        <span class="glyphicon glyphicon-calendar form-group"></span>
                                    </div>
                                {% else %}
                                    <div class="form-group" >
                                        {{ element.label() }}
                                        {{ element.render(['class': 'form-control']) }}
                                    </div>
                                {% endif %}
                            {% endfor %}

I think you should switch places for those two lines:

<div class="form-group" >
{% elseif element.getName() == "txn_date" %}

Yeah...Thanks!! But still it is not working

What's not working stil? If icon appears outside of the form it is either unclosed tag or css issue.

There is no unclosed tag....and what kind of css issue can happen here?

Can you inspect the html with devtools and see what is wrong? Or is it posisble to give link to the problem to check it out?



43.9k

hi,

try to replace " form-group" class of the icon with "form-control-feedback"

If i try to replace with form-control-feedback the icon is displayed at the top of the form



65.0k
Accepted
answer

Now it is working i have changed class in div to form-group has-feedback.

                        <!-- form start -->
                        {{ form("expense/createExpense") }}
                        <div class="box-body">
                            {% for element in form %}
                                {% if is_a(element, 'Phalcon\Forms\Element\Hidden') %}
                                    {{ element }}
                                {% elseif element.getName() == "txn_date" %}
                                    <div class="form-group has-feedback" >
                                        {{ element.label() }}
                                        {{ element.render(['class': 'form-control']) }}
                                        <span class="glyphicon glyphicon-calendar form-control-feedback"></span>
                                    </div>
                                {% else %}
                                    <div class="form-group" >
                                        {{ element.label() }}
                                        {{ element.render(['class': 'form-control']) }}
                                    </div>
                                {% endif %}
                            {% endfor %}
                            <div align="center">
                                {{ submit_button("Create", "class": "btn btn-primary") }}
                            </div>

                        </div>
                        {{ end_form() }}