Joshep95
Joshep95

Reputation: 157

If date is selected, hide icon

I am trying to complete this (easy) task but I can't figure it out. It's easy in my head.

This is the div with icon, input and label:

<div id="datefromto" class="field text-field @if(isset($value)){{ 'active' }}@endif @if(isset($readonly)){{ 'readonly' }}@endif">
        <label>{{ $label }} From:</label>
        <i class="material-icons calendar-icon">access_time</i>
        <input  name="{{ $name }}" type="text" class="datetime" @if(isset($value))value="{{ $value }}"@endif>
    </div>

I tryied this but it's no good:

   $('#datefromto input[type=text]')(function(){
    if ($(this).val()){
        $('.calendar-icon').css("display", "none");
    }
});

Upvotes: 0

Views: 243

Answers (2)

dganenco
dganenco

Reputation: 1616

I would advice you to use input event, instead of change. (based on this answer

 $(".datetime").on('input', function() {
        $('.calendar-icon').toggle(!$(this).val());
    });

Upvotes: 2

sachin kalekar
sachin kalekar

Reputation: 536

Almost there. Add a change handler to your input element where the date is set and hide the icon

    $(".datetime").on('change', function() {
        if(this.val()) {
            $('.calendar-icon').css("display", "none");
        }
    });

Upvotes: 1

Related Questions