I have 3 text boxes.
I have 1 dropdown menu.
When the app starts/page loads, the text boxes are empty and the dropdown is populated with various products.
When I select an item from the dropdown list I load the object into the text fields for editing.
When using properties (this.props), the data loads into the text boxes correctly but I can't make edits to the text because that should be done using state instead.
But, if I use state (this.state), the component never stays in sync. If I select Item 1 from the dropdown it gets loaded into the state but does not render onto the screen until I choose another Item from the dropdown list.
So when I pick Item 2 it then loads Item 1 into the text boxes.
Quote from the React docs.
"setState() does not immediately mutate this.state but creates a pending state transition"
How the heck do you guys deal with this? I feel like I've tried it all.
You need to keep the state in the parent component. The parent would be parent for all those text boxes and to the dropdown menu. From there, you just need to pass callback functions as props to the text boxes and to the dropdown component. In that callback function, you should give the selected dropdown menu item as parameter. And when the function is called, you need to update the content of the text boxes. I think you can do this by keeping state for the three text boxes, that what text is currently displayed. Initially their state would be undefined, so they would show empty. In the state you could track the index and the value.
After that, you need to also pass callback functions to the textboxes. Those callback functions would then track and update the content of the dropdown menu items as you edit the fields. When you edit, you will call the callback, which should update the state, and also render the dropdown menu again with the new content.
Related
I want a user to be able to click a row in the MUI-Datatable, so they can see additional content. The current renderExpandableRow function has the right styling, but I don't want a new row. I want the cell in the first column to show additional data. Is there a way to do this?
Note: I'm also going to need buttons that will expand all/collapse all, so I need a solution flexible enough to do that.
I found a solution to my question.
I made the first column's content a Button using customBodyRender. The column with expandable content became the second column. This column has a customBodyRender with a Collapse component. I store in my component's state all ids of my data objects and whether or not they are expanded. When the Button is clicked, my component's state is updated, which in turn changes whether or not the Collapse component is open.
I also used customToolbar in the table options to generate an expand all/collapse all button, which just sets the state of all rows to expanded/collapsed.
I have large form of combobox's (about 65 of them). Depending on the permissions of the user I would like the comboboxes to react differently.
For one level I would like the combobox to react as normal, show the list, allow changes etc.
For another level I would the combo to react to the click, but not show the dropdown menu and trigger different code.
I can't use the .enable property because I still need clicks from the lower level user to trigger something. I've "e.cancel" in previous code but the click event on a combo box doesn't seem to like it.
Error BC30456 'cancel' is not a member of 'EventArgs'
Any ideas what I might be missing here?
I have a regular element io input field fetching some results that I would like to add to an array straight from the autocomplete-suggestions. I've added a button to the suggestions but the select event in the autocomplete keeps getting triggered, is there anyway around this ?
I am making a chat application using XAML in UWP.The side panel is consisting of users. like this.
Everything is in Listbox in which I have this template that consists one ellipse as a circle which is like an indicator,one user image,textblocks and one toggle switch.I have to give states to the toggle switch in on the state it should change the green color of circle and make it red.
I want to give this functionality in code c# in MainPage.cs. I made the object of toggle in toggled Event Handler but I am not able to access the other elements inside the data template like ellispse,textblock.
What is the other alternative way of doing this?
NOTE: It has to be in listbox because I want to use the same template for every user.
The best way to do this would be to use data binding.
You would define a ViewModel class for the item, which would contain a bool property and would react to the toggling of the switch in the setter or have a Command which you would execute when the state event changes using behaviors.
If you really want the code as a event handler on main page, you have some options. To get the item associated with the toggle, you can use its DataContext property and cast it to the data type you are using. Alternatively, you can use Visual Tree Extesnions provided by the UWP Community Toolkit. This enables you to find the parent (probably Grid) where you store all the item controls and then manually find the user image, TextBlock, etc.
I want to have a repeater like DataView or ListView. The first column of each row (named User ID) should be read from a List, and for each user ID, the program should dynamically create three radio buttons like these:
Requirements:
The user must able to change selection of radio buttons.
When the user clicks the submit button, radio values be displayed using the info("") method.
I've already done this by using this example, but when I click the submit button, old selections are shown, and the form gets reset to those old selections.
This example code might be helpful.
ListView doesn't play very well with form components, but it may work if you call ListView.setReuseItems(true);.