Я пытаюсь добиться изменения от материализации select
до text[input]
ввода, когда пользователь нажимает Other
Я пытался использовать .replaceWith()
, instance.destroy();
и $(this).remove()
все безрезультатно.
HTML:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<h5>Materialize select</h5>
<div class="row">
<div class="input-field col s12">
<i class="material-icons prefix">device_hub</i>
<select id="mySelect" class="change_select_to_text_on_other">
<option value="" selected>Choose "Other" to trigger!</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="other">Other</option>
</select>
<!--This is what I would like replace the select option with when other is clicked!:
<input id="first_name" type="text" class="validate">
<label for="first_name">Make your own selection!</label-->
</div>
</div>
JS:
var $select1 = $('#mySelect');
$select1.material_select();
$select1.on('change', function (e) {
if(e.target.value == 'other'){
$( this ).replaceWith( "<h2>New heading</h2>" );
var instance = M.FormSelect.getInstance($(this));
instance.destroy();
}
});
Скрипка
Когда пользователь нажимает на другую опцию, выберитезаменяется вводом текста.
Спасибо!