Reputation: 45
I have a master/detail relation similar to the relations sample provided. In my example department has a one to many relationship with employee I have a form widget(department) which has a button to insert an employee.
when I click on that button the correct dialog form is displayed but I am allowed to enter any department which I do not want. I am looking to have the relation defaulted to the "parent" widget where it was clicked and ideally not be editable.
Upvotes: 0
Views: 586
Reputation: 825
It's hard to give an exact answer without seeing your app, but you should probably replace the dropdown in the form with a label, that will make it not editable. You can bind the value of the label to the relation just like the value of the dropdown was bound.
A slightly easier option would be disabling the dropdown (look for the Enabled probably in the property inspector). But that could be confusing for your users since they might think it should be editable.
(Alternatively, you could just remove the field altogether if it's not important to show the relation.)
I think this only answers the "not editable" part of your question, if you want it to be pre-filled you either need to do some scripting, or use relation data sources.
I suggest using relation data sources, so right now you probably have something like:
app.datasources.Emp.create()
, which creates a new employee.
Instead, you can use widget.datasource.relations.Emp.create()
, which will create a new employee which has a relation to the current item in widget.datasource. If this button is placed in your department form widget, then that means it will create an employee related to whatever department is shown in the form.
Note that none of this stops users from changing the department of an employee, it just changes the UI. In lots of cases that is enough, but you may also want to add some server-side security controls if it's important to limit which users can create employees, change departments, etc: See https://developers.google.com/appmaker/security/secure-app-data
Upvotes: 3