Angular radio buttons and custom input - angularjs

I am trying to set up a form, with some radio buttons and a textarea for custom input. If I select custom input, and start typing it loses the radio selection and I must select the custom input again when I am done typing
http://jsbin.com/AMAniXu/2/edit
How can I ensure that selecting the radio next to the textarea and providing custom input maintains user selection?

Use a different model object other than the object used in the ng-value of the checkbox
<input type="radio" data-ng-model="selectedEntry" data-ng-value="newText">
<textarea rows="4" cols="40" data-ng-model="newTextInput"></textarea>
And then you can grab the value in the model newTextInput when you click the submit button if the third one is selected.
DEMO

Related

React text field's default value doesn't get overriden

I'm creating a react form which has 2 input fields with a condition that is only triggered when the local state has a particular value. I've set a default value as well which is used to populate some values based on button click. But if I already type in some text and then click the button, the values don't over ride the existing. Here's the code-
<input type="text" name="name" ref={register} defaultValue={state.isEdit? data[idx].name:undefined}/>
So normally textfield is blank and when I click on a table that has some student details, the corresponding value is displayed on field.[Working], but now if suppose I have already typed in something, and then click on edit button from table, the student details don't reflect on text field.
P.S. - I'm not looking for placeholder. Also this form uses react-hook-form

How to get the selected radio button in the Kendo Grid

I have a kendo grid with a column consisting of radio buttons.
I want to make the radio buttons act as radio buttons(check only 1) and get the selected 1.
Here is a sample Demo
You were pretty close. First a few things about radios:
Radio buttons are grouped using the name attribute
Radio buttons are bound to labels via the for attribute on the label element matched with the id attribute on the radio button
The problem with your code is that all radios have the same id, which is why clicking any radio button toggles the first one ... because the first element found with that id is grabbed, with the assumption that there'd only be one.
In order to fix this, you need a unique id for each radio button, and you can do that by referencing the EmployeeID in the data source using the #: EmployeeID# notation, as exemplified in the docs
Therefore your template would look like this:
template: '<input type="radio" name="customer" id="customer_#: EmployeeID#" class="k-radio"><label class="k-radio-label" for="customer_#: EmployeeID#"></label>'
Please find working example here: https://dojo.telerik.com/aRuQubep/5
Hope this does the job :)

Incorrect radio button getting selected for ng-repeat radio buttons

I have a list of radio buttons using ng-repeat.
When I initially load the page and select on the last radio button, the button on it's side gets selected.
This only happens for the first time, i.e. if I click on the last button a second time, it is selected correctly.
<input type="radio" name="rb" value="{{rbCollection.name}}" data-ng-click="open(name)" data-ng-model="Ctrl.selection">
Check this so.
The problem is that ng-click fires before the ng-model code that updates the scope. If you change it to use ng-change, that will fix it. You also need to add ng-change to your text box to update the scope as the user types.

How can I wire up a button on my page so that it is clicked when a user presses enter?

I have many buttons on my page but none are inside a form. I already assigned one button and changed its color so it shows as a bootstrap primary button.
How can I make it so that when a user is on the page and they click enter then the button click event for that button is called?
I am not sure about what you are asking; but you can do the following, if you have a controller with the function add() attached to the scope:
<form ng-submit="add()">
<input type="text" ng-model="myModel">
<input type="submit" value="Add"/>
</form>
The above adds the value entered in the input to the model.
I suggest using a <form ...> around your elements. Because if you rely on a custom keypress detector, and you have more than one button, it will activate all of them. The <form ...> dictates which button is to be submitted when a user is in a particular input field and hits Enter.
Your form doesn't even need to have an action="..." or method="...". You could just as well use ng-submit="yourFormParser()".
ng-submit will not useful to you, because your form submit event is different.
The only option remains is, you can take use of ng-enter directive, but you should manually bind it wherever you want. I believe this is last option.
ng-enter="myEvent()"
HTML
<input type="text/url/email/number/checkbox/radio" ng-model="test" ng-enter="myEvent()"/>
Hope this could help you, Thanks.

How do I disable form validation for ng-click?

I have a form where certain inputs have "required" attribute. I also have a button that adds form fields when clicked, but it always triggers the form validation message when the required fields are not filled out. I only want form validation to trigger for ng-submit and not ng-click. Is this possible?
If you have a look at the W3C specification, it would seem like the obvious thing to try is to mark your button elements with type='button' when you don't want them to submit.
The thing to note in particular is where it says
A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit"
when you do not want submission on specific button then define type="button". it will 100% work
Use novalidate for your form:
<form name="aForm" novalidate>
or use ng-form instead:
<div ng-form name="aForm">
Check this link for further info about form validation in AngularJS.

Resources