Roam
Roam copied to clipboard
Make a field in a form conditionally required
Is it possible to make a field required based on other choises? E.g. the two attributes (fields) htype (combo box, set to required in the Roam Config Manager) and bebodd (option row, not set to required in the config manager). If the user has chosen htype=1, then the "bebodd" is not required. But, if the user choose htype=2, then "bebodd" must be chosen as well (i.e. must be set to required). I have manged to display a message (warning) for 4 seconds if htype=2 (however if the user ignores this message and clicks Save, the digitized featuer is saved (with bebodd=Null) through python-code in the corresponding form.py. I would like bebodd to be set to required (if htype=2) and that Roam would show the "default" warning "Missing fields: Some fields are still required" untill bebodd is chosen. I have tried different versions of
self.boundwidgets['bebodd'].config.get('required',True)
without any luck so far.
(And, not crucial, is it possible to add a red star indicating that bebodd has been set to required?)
An update ("solution"): I carried out some sort of a "workaround". By the means of if-then-cases, I manged to alert the user that some fields had to be entered (even though there were not required from the very beginning - not having a red star) before saving. However, now I'm facing the opposite problem: A field is normally required (set in the Roam Config Manager; giving the field a red star in Roam), but in some few cases, it is not required. Example: The field operator has to enter different data about a historical house (state, colour on the walls and inhabited (or not) is required), but if the house is demolished, only the state (=demolished=code 5) should be required in this case. The red star next to colour (a) and inhabited (b) should turn grey/set to False/disappear. I have tried different variations as e.g.:
if ( self.boundwidgets['o1mrk'].value() in ["2","5"] ):
self.boundwidgets['a'].setrequired = False
self.boundwidgets['b'].required = False
But no, the fields "a" and "b" will still be required (having the red star). A silly workaround is that the user chooses whatever he/she want for "a" and "b", and then when saving whatever value selected for "a" and "b" is deleted automatically with
liste1 = ['']
self.boundwidgets['a'].config = dict(list=dict(items=liste1))
self.boundwidgets['b'].config = dict(list=dict(items=liste1))
But this is annoying (and slightly time consuming) for the user in the long run. There should be a better way/solution - shouldn't it?
I'd like to recommend this enhancement as well. One thing I've noticed that Roam doesn't do so smoothly is workflows involving updating the same data point multiple times. In our workflow, a data point being updated will have one of a few final states (Negative, Positive, Suspicious), and depending on that final state, some fields should be conditionally required. Adding better support for this (even if only in the config files and not the config manager) would make QA'ing the data easier and reduce errors.
This current feature is in progress at the moment.
On Tue, Apr 12, 2016 at 1:21 AM, Kevin Davis [email protected] wrote:
I'd like to recommend this enhancement as well. One thing I've noticed that Roam doesn't do so smoothly is workflows involving updating the same data point multiple times. In our workflow, a data point being updated will have one of a few final states (Negative, Positive, Suspicious), and depending on that final state, some fields should be conditionally required. Adding better support for this (even if only in the config files and not the config manager) would make QA'ing the data easier and reduce errors.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/DMS-Aus/Roam/issues/283#issuecomment-208398994
@9ls1 Do you happen to remember the code you used to do this? I'm trying to do something similar and can't figure out how to prevent the feature from being saved.
@karzak Which code (other than mentioned in my comment 1 July 2015) are you looking for? To give an alert I added e.g. this code:
def handler(self, value):
...
if ( self.boundwidgets['htype'].value() in ["2","3"] ):
RoamEvents.raisemessage('Kremt...','Fyll ut I bruk',1,4,'Hovedtype = 2, eller 3 og I bruk maa angis.')
Due to improvements in QGIS regarding widgets (default values, constraints, tabs, grouping), easy turning layers on and off and the use of expressions for symbols and labels (case-when-logic to change colours to make it easier to check if I have revisited every object), I'm using pure QGIS for data collection in field. However, I miss a "option row"- widget in QGIS - that would save me a lot of clicking. (May ver. 2.5 of IntraMaps Roam be more flexible?)
[Forms] Form widget events. Events can be used to change other values or show/hide other controls.