V
V
vnpp2018-06-02 01:33:23
Yii
vnpp, 2018-06-02 01:33:23

How to bind datalist to MaskedInput in YII2?

To speed up data entry, it is convenient to pull up existing ones. If control by input mask is needed, as a rule, MaskedInput is used, it is possible to bind a datalist to it in a standard way through the list property ("arrow" that there is datalist data), but the drop-down list itself with values ​​does not appear.
How to bind datalist to MaskedInput or change MaskedInput / JS so that the connection works correctly?
ps Missing code

echo MaskedInput::widget([
            'name' => 'tel',
            'value'  => !empty($mytel) ? (string) $mytel: '',
            'mask' => '+7 (999) 999-99-99',
            'options' => ['list' => 'tel_old'],
            ]);
echo '<datalist id="tel_old">';
echo Html::renderSelectOptions(null,['+7 (495) 123-45-67']);    
echo '</datalist>';

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vnpp, 2018-06-02
@vnpp

the code

echo MaskedInput::widget([
            'name' => 'tel',
            'value'  => !empty($mytel) ? (string) $mytel: '',
            'mask' => '+7 (999) 999-99-99',
            'options' => ['list' => 'tel_old'],
            ]);
echo '<datalist id="tel_old">';
echo Html::renderSelectOptions(null,['+7 (495) 123-45-67']);    
echo '</datalist>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question