Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ReadOnly Field on selection change of select field. #966

Open
codemakeup opened this issue Dec 3, 2017 · 7 comments
Open

Update ReadOnly Field on selection change of select field. #966

codemakeup opened this issue Dec 3, 2017 · 7 comments

Comments

@codemakeup
Copy link

codemakeup commented Dec 3, 2017

Hi, after looking a lot of your suggestion I have come so far that I am able to update a text field where editing = true when I change the selection on select field. But I want to keep that text field editing = false.
Below is working code where I want to make "Unit" field as ReadOnly and still able to update from Selection Change of "Item" field .

fields: [
                    {
                        name: "foodItemId", type: "select", valueField: "id", textField: "name", title: "Item", width: "35%", validate: "required", align: "left",
                        items: foodItems,
                        editTemplate: function (value, item) {
                            var grid = this._grid;
                            var $editControl = jsGrid.fields.select.prototype.editTemplate.call(this, value);
                            $editControl.change(function (value, item) {
                                var selectedValue = $(this).val();
                                $.each(foodItemsDataService.foodItems, function (i, item) {
                                    if (item.id == selectedValue) {
                                        grid.fields[1].editControl.val(item.unit.name);
                                        grid.fields[2].editControl.val(item.caloriesPerUnit);
                                    }
                                });
                            });
                            return $editControl;
                        }
                    },
                    {
                        name: "foodItem.unit.name", title: "Unit", type: "text", width: "15%", editing: true
                    }
@tabalinas
Copy link
Owner

Could you provide a jsfiddle to demonstrate the issue?

@codemakeup
Copy link
Author

codemakeup commented Dec 9, 2017

I am quite new at JS but I will try to create a Fiddle and share it. In mean time let me explain what i am doing.
I get my data for the select field from a restful service call and it has three fields. Food item, Unit, and Cals. per Unit. User has to enter a value for each food item he/she selects. So user is only entering Two fields. Food Item (select field in the grid) and Value (Text Field). The other two (Unit and Cal.s per unit) are part of my object which I get from service. I dont want these fields to be entered by user so I keep it Readon Only (RO). But in doing so when I flip through Food Items Select, these two field dont get updated. If I keep them not RO then and return $editControl as show in my original post, it get updated fine.

So long story short. When I select an item from Select field I want to update a RO field with some values based on what I have selected. Is it even possible or do I have to keep as Editable fields?

By the way, I am sorry for the long explanation, i just want make it as clear as possible.

@codemakeup
Copy link
Author

codemakeup commented Dec 9, 2017

Here is jsfiddle: https://jsfiddle.net/cpm8ze6t/
On Edit, when i select food item, the calories field which is readonly, should be updated as per what is selected. Its not 100% working fiddle but i hope you will get the idea.

@tabalinas
Copy link
Owner

Checkout the comment to the issue #71 (comment).
This should be similar to what you are trying to accomplish.

@codemakeup
Copy link
Author

codemakeup commented Dec 11, 2017

Hi, thank you for your help. Yes your are right that it is similar to what I am looking for. But in this fiddle http://jsfiddle.net/n982uvx1/19, I want to keep the Team column read only and dont want it as Select field. It working perfectly with the selection change but I don't want user be able to change the value which is auto filled by selection in Department Field. Please let me know if I am still not making it clear in what I am looking for.

@arminus
Copy link

arminus commented Dec 18, 2017

@codemakeup - did you find a solution to your problem? (your fiddles are gone) I'm facing the same issue right now...

In my words: the problem seems to be that there is no editControl if the field is set to editing = false - so I guess another question would be if editing true|false can by dynamically changed (i.e. true right before the .editControl.val(...) call and back to false right after?

@codemakeup
Copy link
Author

@arminus - I didnt find any solution yet. My app is still in dev so I am keeping the fields in Edit mode. If what you are saying works (editing true|false can by dynamically changed ) that could solve the issue too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants