question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support indexer use in InputBase

See original GitHub issue

Is your feature request related to a problem? Please describe the problem.

I’m looking to create a group of InputCheckbox components, and have all of their values stored in Dictionary<object, bool> where the value indicates if the checkbox is checked or not. Logically I tried something like:

@foreach(var kvp in dict) {
  <InputCheckbox @bind-Value="dict[kvp.Key]"></InputCheckbox>
}

This doesn’t work though, as the indexer on Dictionary<> is actually an InstanceMethodCallExpression1, and thus runs afoul of FieldIdentifier’s “MemberExpressions only rule”, throwing The provided expression contains a InstanceMethodCallExpression1 which is not supported. FieldIdentifier only supports simple member accessors (fields, properties) of an object.

https://github.com/dotnet/aspnetcore/blob/dc98f4b9580fde664c6ae88f9712467ff8e96bc4/src/Components/Forms/src/FieldIdentifier.cs#L103-L106

Creating a wrapper around my dictionary boolean does solve the problem, however, as the expression is once more a member access:

class BooleanWrapper {
  public bool Value { get; set; }
}

//...

Dictionary<object, BooleanWrapper> dict = new();
@foreach(var kvp in dict) {
  <InputCheckbox @bind-Value="dict[kvp.Key].Value"></InputCheckbox>
}

Describe the solution you’d like

It doesn’t seem like it’d be too difficult to get FieldIdentifier to support simple index access by adding some additional logic to ParseAccessor that follows calls to get_Item on arrays or dictionaries. I’d be happy to write the PR for it myself if there was any interest in such a thing.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oiBiocommented, Jun 10, 2022

you BoolWrapper class works, you just need to but the object in a inline variable first. Like this

    @foreach (var kvp in dict)
    {
        var obj = dict[kvp.Key];
        <InputCheckbox @bind-Value="obj.Value"></InputCheckbox>
    }
0reactions
javiercncommented, Jun 28, 2023
Read more comments on GitHub >

github_iconTop Results From Across the Web

Material ui InputBase can not be hided by other elements
Something odd was going on with the z-index. ... import { InputBase } from "@material-ui/core"; const useStyles = makeStyles((theme: Theme) ...
Read more >
Class: inputBase
Abstract inputBase component. Validation and Messaging. An editable component runs validation (normal or deferred) based on the action performed on it ...
Read more >
InputBase API - Material UI
It aims to be a simple building block for creating an input. It contains a load of style reset and some state logic....
Read more >
@mui/material InputBase TypeScript Examples
This page shows TypeScript code examples of @mui/material InputBase. ... The following examples show how to use @mui/material#InputBase.
Read more >
Render Lists | Lightning Web Components Developer Guide
To render a list of items, use. ... The wireGetPicklistValues component in the lwc-recipes repo uses the lightning-input base component to display a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found