I'm trying to create a form using Angular Material which allows user to select number of items per page (loaded from DB, or whatever). I want to have most popular choices (e.g. 10, 20, All) always visible and accessible with a single mouse click, so no drop-down list or slider. However I also want the user to have the freedom to specify custom value through an input field (see image below).
I created following JSFiddle: http://jsfiddle.net/p55sx0zy/
However there is a problem. Input field cannot be focused with mouse, instead radio button is selected and I need to press TAB
to focus the input field. When I do that and change the value radio button gets unselected. Then when I press this 4th radio button again the proper value is reported.
I'd like this input to be focusable with mouse and the radio button to remain selected while input is being modified. Is it possible to achieve such design at all with Angular Material?
Using Input Radio checked property: The Input Radio checked property is used to return the checked status of an Input Radio Button. Use document. getElementById('id'). checked method to check whether the element with selected id is check or not.
How do I preselect a radio button in HTML? The radio class is a simple wrapper around the <input type="radio"> HTML elements. You can check a radio button by default by adding the checked HTML attribute to the <input> element.
Defining Radio Group in HTML We can define a group for radio buttons by giving each radio button the same name. As and when the user selects a particular option from this group, other options are deselected. Following is an example of radio buttons with different names within a form.
CSS is preventing the input from being interacted with.
md-radio-button .md-label, .md-switch-thumb .md-label {
...
pointer-events: none;
}
You can just override the style:
HTML:
<md-radio-button ng-if="option.input" value="{{ctrl.perPageCustom}}" class="md-primary md-radio-interactive">
<input ng-model="ctrl.perPageCustom" /> (Custom)
</md-radio-button>
CSS:
.md-radio-interactive input {
pointer-events: all;
}
Modified fiddle: http://jsfiddle.net/langdonx/p55sx0zy/1/
You'll have to change you tack on how you're storing the custom value so the radio stays selected though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With