JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Buttons › Group of radio buttons in a Angular react form – how to retrieve value of radio
Tagged: smart radio button
- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by davout.
-
AuthorPosts
-
July 28, 2021 at 5:25 pm #102103davoutMember
I have a set of ‘smart-radio-button’ components defined in my Angular 10 React form
I can’t work out how to set the starting selection and when I click on a radio button the angular Form Group control has a value of ‘true’ rather than the value assigned to the button<smart-radio-button class="recurring-interval-radio" [value] = "'0'" [groupName]="recurringInterval" formControlName="recurringInterval" (change)="onRecurringIntervalChange('0')">None </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" [value]= "'1'" (change)="onRecurringIntervalChange('1')">Daily </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" [value]="'2'" (change)="onRecurringIntervalChange('2')">Weekly </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" [value]="'3'" (change)="onRecurringIntervalChange('3')">Monthly </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" [value]="'4'" (change)="onRecurringIntervalChange('4')">Yearly </smart-radio-button>
Can you please provide a small example of a group of radio buttons working in a react form?
July 29, 2021 at 2:46 pm #102111YavorDashevMemberHi davout,
AS from you post I suggest that you want to get the value of the smart-radio-button component and not its boolean value.
If so you can do so using the change event and using you method://In your app.component.ts file onRecurringIntervalChange(event:any):void { let radioButtonValue: EventTarget = event.target.value; console.log(radioButtonValue) }
And for the starting selection it depends on which of the radio buttons you set the
checked
property and if you don’t set it to either of them none of them will be selected.
Let me know if that works for you!
Please, do not hesitate to contact us if you have any additional questions.
Best regards,
Yavor Dashev
Smart UI Team
https://www.htmlelements.com/August 25, 2021 at 1:09 pm #102147davoutMemberI am using Angular reactive forms, where I pushing data into the controls programmatically using ‘setValue’ and ‘patchvalue’.
Neither of those methods seems to work for ‘smart-redio-button’August 25, 2021 at 1:25 pm #102148davoutMemberI’ve created a version of my form using basic input type=radio, and that works.
Using your ‘smart-radio-button’ component it does not work
<div class="recurring-intervals"> <!-- <div style="margin-left: 5px; margin-top: 5px; overflow: visible">--> <!-- <input type="radio" id="recurringIntervalNone"--> <!-- value="0" name="includeRecurringTasks" formControlName="recurringInterval">--> <!-- <label for="recurringIntervalNone">None</label>--> <!-- </div>--> <!-- <div style="margin-left: 5px; margin-top: 5px; overflow: visible">--> <!-- <input type="radio" id="recurringIntervalDaily"--> <!-- value="1" name="includeRecurringTasks" formControlName="recurringInterval">--> <!-- <label for="recurringIntervalDaily">Daily</label>--> <!-- </div>--> <!-- <div style="margin-left: 5px; margin-top: 5px; overflow: visible">--> <!-- <input type="radio" id="recurringIntervalWeekly"--> <!-- value="2" name="includeRecurringTasks" formControlName="recurringInterval">--> <!-- <label for="recurringIntervalWeekly">Weekly</label>--> <!-- </div>--> <!-- <div style="margin-left: 5px; margin-top: 5px; overflow: visible">--> <!-- <input type="radio" id="recurringIntervalMonthly"--> <!-- value="3" name="includeRecurringTasks" formControlName="recurringInterval">--> <!-- <label for="recurringIntervalMonthly">Monthly</label>--> <!-- </div>--> <!-- <div style="margin-left: 5px; margin-top: 5px; overflow: visible">--> <!-- <input type="radio" id="recurringIntervalYearly"--> <!-- value="4" name="includeRecurringTasks" formControlName="recurringInterval">--> <!-- <label for="recurringIntervalYearly">Yearly</label>--> <!-- </div>--> <smart-radio-button class="recurring-interval-radio" value = "0" [groupName]="recurringInterval" formControlName="recurringInterval" (change)="onRecurringIntervalChange('0')">None </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" value= "1" (change)="onRecurringIntervalChange('1')">Daily </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" value="2" (change)="onRecurringIntervalChange('2')">Weekly </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" value="3" (change)="onRecurringIntervalChange('3')">Monthly </smart-radio-button> <smart-radio-button class="recurring-interval-radio" [groupName]="recurringInterval" formControlName="recurringInterval" value="4" (change)="onRecurringIntervalChange('4')">Yearly </smart-radio-button> </div>
August 26, 2021 at 4:47 am #102151adminKeymasterHi davout,
We cannot reproduce an issue with the provided details. If you share a stackblitz sample which shows your scenario and the behavior which you report, we will try it once again.
Best regards,
Peter Stoev
Smart UI Team
https://www.htmlelements.com/August 26, 2021 at 12:07 pm #102154davoutMemberI’m new to this developer area, how do I create a StackBlitz example?
I can’t see why you don’t have a stackblitz demo for every component in this product
-
AuthorPosts
- You must be logged in to reply to this topic.