Conversation
| --- | ||
| category: forms | ||
| title: Add Grouped Radio Buttons with Custom Toolbar Button | ||
| description: Create a custom toolbar item that programmatically places pre-grouped radio buttons with a single click, avoiding manual renaming. |
There was a problem hiding this comment.
what does pre-grouped means here?
There was a problem hiding this comment.
It means radio buttons are created with the same formFieldName, so they automatically function as a group
There was a problem hiding this comment.
aren't they called grouped?
| defaultValue: "1", | ||
| }, | ||
| ); | ||
| await instance!.create([radioWidget1, radioWidget2, formField]); |
There was a problem hiding this comment.
The ! here is the non-null assertion operator—it tells TypeScript "trust me, this isn't null." Since instance is typed as Instance | null, what's the intended behavior if it actually is null at this point? Should it:
- Fail loudly (current behavior with ! if null at runtime)
- Silently skip the call (use
?.) - Something else (explicit check with error message?)
There was a problem hiding this comment.
I already worked on something similar btw: #155
There was a problem hiding this comment.
@veroo-m , if I correctly understood your comment, I've added an if (!instance) return. Is that right?
There was a problem hiding this comment.
@eli7pm , I see that yours auto-groups them widgets during manual creation in Form Creator mode, while mine provides a toolbar button for programmatic placement of grouped radio buttons. I was reluctant at first to close this one, but I think they're both useful for different workflows + this one adapts Rahul's new Playground structure.
There was a problem hiding this comment.
I would use await instance?.create([radioWidget1, radioWidget2, formField]);
|
Tested with Miguel's project to test and it seems to be working |
Added an explicit if (!instance) return
Updated the description to clarify that radio buttons are grouped.
|
@veroo-m , could you please review this? |
Adding a new playground example demonstrating how to create a custom toolbar button that programmatically creates pre-grouped radio buttons with a single click.