Невозможно выбрать переключатель в MaterializeCSS, когда есть два идентификатора - PullRequest
0 голосов
/ 06 июля 2018

У меня есть переключатель входа с двумя разными идентификаторами, привязанными к нему

<input type="radio" checked id="setProxyBtn" data-profileid="direct"/>
<label for="setProxyBtn">direct</label>
<input type="radio" checked id="setProxyBtn" data-profileid="fixed_servers"/>
<label for="setProxyBtn">fixed_servers</label>

Я попробовал этот подход ...

<input type="radio" checked id="setProxyBtn" data-profileid="direct"/>
<label for="direct">direct</label>
<input type="radio" id="setProxyBtn" data-profileid="fixed_servers"/>
<label for="fixed_servers">fixed_servers</label>

тоже попробовал этот подход ...

<input type="radio" checked id="setProxyBtn" data-profileid="direct"/>
<label for="setProxyBtn direct">direct</label>
<input type="radio" id="setProxyBtn" data-profileid="fixed_servers"/>
<label for="setProxyBtn fixed_servers">fixed_servers</label>

Кажется, что ни один из них не позволяет пользователю выбрать вторую радиокнопку, какие-либо указания относительно того, что я могу делать неправильно?

Ответы [ 2 ]

0 голосов
/ 06 июля 2018

Нашел решение, поскольку @light указал, что я использовал один и тот же идентификатор для обоих. Поэтому я сделал динамический идентификатор и использовал jquery для прослушивания событий в элементах, которых еще нет в DOM.

base.html код изменен на ...

<input type="radio" checked id="setProxyBtn_direct" data-profileid="direct"/>
<label for="setProxyBtn">direct</label>
<input type="radio" checked id="setProxyBtn_'+profileId+'" data-profileid="'+profileId+'"/>
<label for="setProxyBtn_'+profileId+'">'+profile_desc+'</label>
Код

base.js изменен на ...

$(document).on('click', '[id^=setProxyBtn_]', function(){
0 голосов
/ 06 июля 2018

Вы пытались добавить атрибут name?

<input type="radio" name="radioButtonGroup" checked id="setProxyBtn" data-profileid="direct"/>
<label for="direct">direct</label>
<input type="radio" name="radioButtonGroup" id="setProxyBtn" data-profileid="fixed_servers"/>
<label for="fixed_servers">fixed_servers</label>

Источник: https://materializecss.com/radio-buttons.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...