Add enable_when attribute to the input#758
Conversation
- Introduced `showInput` and `conditionalShowInput` functions to manage input field visibility based on conditions defined in `show_if`. - Updated `InputFields` component to utilize the new visibility logic. - Added new utility functions in `InputHelpers` for value normalization and comparison. - Extended `TestInput` model to include `show_if` property for conditional rendering. - Added tests to ensure correct rendering behavior based on input conditions.
- Simplified `sortAndNormalizeArray` function to directly handle arrays. - Improved input construction and visibility assertion logic in tests. - Added new tests for input visibility based on conditional rendering and hidden states. - Ensured consistent naming conventions in test helper functions.
- Added `show_if` field to the input serializer for conditional rendering. - Updated documentation to include `show_if` in input options. - Included `show_if` in the list of uninheritables for input attributes to ensure proper handling during input definition merging.
- Introduced a new group for conditional inputs in the demo suite. - Added tests for various input types that display based on the selected option. - Enhanced the input structure to support conditional visibility using the `show_if` attribute.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #758 +/- ##
==========================================
+ Coverage 84.78% 84.82% +0.04%
==========================================
Files 297 297
Lines 13969 14008 +39
Branches 1955 1975 +20
==========================================
+ Hits 11843 11882 +39
Misses 2118 2118
Partials 8 8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
karlnaden
left a comment
There was a problem hiding this comment.
Note additionally the missing test coverage.
| list_options?: InputOption[]; | ||
| mode?: string; | ||
| }; | ||
| enable_when?: { |
There was a problem hiding this comment.
Please propose updated Inferno documentation in this section (rendered here) for this input feature.
There was a problem hiding this comment.
| }; | ||
| enable_when?: { | ||
| input_name: string; | ||
| value: string | string[]; |
There was a problem hiding this comment.
There's a decent amount of added complexity to support string[] here for unclear benefit. Technically it allows you to use a multi-select checkbox field as a target for the enable-when, but in practice you would be enabling for a specific set of boxes checked and not able to enable based on a single checkbox. You don't have any examples or unit tests for this case, so I think my request is to take it out and explicitly document that enable_when is meant to target inputs with the radio type. That is the primary use case and I think better to keep this simple (as you've already done) than try to make it fully general.
There was a problem hiding this comment.
I have changed this attribute to a string type and also added an example with the select input.
- Removed the `isEqual` function in favor of direct normalization comparison for input visibility logic. - Updated `TestInput` model to restrict `enable_when.value` to a single string instead of an array. - Enhanced demo suite tests to include new radio and select input types with conditional visibility. - Improved test specifications to reflect changes in input structure and visibility conditions.
|
Hello Karl @karlnaden All problems should now be resolved on my end. |
| constructInput({ | ||
| name: 'dependent', | ||
| title: 'Dependent', | ||
| enable_when: { input_name: 'trigger', value: ['a', 'b'] }, |
There was a problem hiding this comment.
should the value be a string rep of the Array? Or is use with checkboxes disallowed?
|
Hello team, I was busy this week, but I hope to continue work on the request next week. |
@projkov Are you able to get this PR finished in the next week or two? We'd like to include it in the Inferno May release. |
|
@projkov checking in again to get a sense for your timeline on this enhancement. |
|
Hello Karl @karlnaden |
No worries @projkov - this week would be great. We have some planned releases coming out in early June that would use this feature if it were available. Thanks for helping to improve Inferno. |
…ole warnings for missing inputs. Update tests to verify behavior for checkbox selection order and conditional visibility logic.
|
Hello Karl. @karlnaden Looks like if the conditional field is required, it could be a problem in cases where it is hidden and doesn't have a value. |
Define what you mean by "problem" here. If it is a crash in the UI, then we'd need to do something about it. If it is just a "you can't successfully run this test because your design doesn't display an input that you need to populate", that already exists (see the existing demonstration suite, for example) and I don't think that we need to over engineer logic to detect it and surface it. In summary, assuming this is just a situation where design decisions can make your tests unrunnable in the UI, I don't think you need to detect or log that. |
|
@projkov is this ready for review, or are you still working on it? |
…d add checkbox options and default value methods in demo suite tests.
|
Hello Karl @karlnaden I have doubt about how conditional rendering should work with checkbox field. Right now it works only when a single specific checkbox is selected. It looks strange from my perspective. What do you think? |
I agree that only working when one checkbox is populated does not meet the spirit of checkboxes. I wonder if for this initial pass at this functionality only radio-type inputs are supported (matches the single selection). I think that is useful even if it isn't fully general. Do you have a specific case that needs checkbox support? If so, then it would be better to re-think the design to support multi-selection cases. |
Right now, I don’t have any cases where a checkbox field is suitable. Let’s keep it simple and not provide this functionality for checkboxes. If someone needs this feature, then we can think about it in the next iteration. |
…nused checkbox tests from demo suite.
karlnaden
left a comment
There was a problem hiding this comment.
Code coverage flags are related to lint, so fine to skip.
Please address my comments on the documentation PR and then I will merge them both in.
Short description
Branch adds conditional visibility for inputs in the inputs modal: inputs can be shown or hidden based on another input’s value via a enable_when condition.
Change overview
1.1 showInput and conditionalShowInput in the client
1.2 TestInput extended with enable_when
1.3 Value normalization/comparison helpers
1.4 InputFields switched from !input.hidden to showInput(input, inputsMap)
2.1 Refactors and tests for conditional visibility and hidden state
3.1 Backend: enable_when on input entity and API serializer
3.2 enable_when treated as uninheritable (like locked / hidden)
4.1 New optional demo group “Conditional Inputs Group” using enable_when (e.g. “How to get Bundle” → paste JSON / URL / $summary with different inputs)
5.1 bin/inferno: added require 'bundler/setup'
5.2Gemfile.lock: added arm64-darwin-25 platform
References:
Usage example:
Demo: