Hola Geniuses of ArcGIS FieldMaps,
I need a workaround for the following situation: I have some field with CODES that I would like to represent with a Switch (elegant, quick, and use less space on the form.) I defined default values for the fields so the switch works fine.
The thing is if the user activates the switch for CODE D (dead tree) all remaining code switches are hidden. Fine. But if you activate the CODE D again (a mistake) the elegant switches are replaced by list boxes. The reason? The hiding operation cleared the default values and wrote Null on the fields, making the switches useless. See the attached screenshots.
I know this is a expected behavior, but is clearing default values on the fields! Is there anything I can do to use the switches?
Milton
Solved! Go to Solution.
you can give the "$originalFeature" variable type a try to help with this. you might be able to get the previous state of the field and reassign it.
Also, perhaps a helper field that you keep visible at the bottom of your form that has a calculation that only executes with the state of any switch is toggled and stores a dict representation of the state of your form. If the a switch is turned on and hides fields it records the previous values of each field that is subsequently hidden... if that switch then turns back off those values could be used by calculations on your other fields to restore their values. I have not tried this, but seems sound in theory.
A value being wiped when you hide the field is the expected behavior, for better or worse.
A workaround looks like the following:
The gist is that each switch would need to calculate itself when not hidden, then there needs to be an editability expression set for each switch that said, if I have a value then make me editable (which disables the calculation) or if I'm null calculate me... which makes me editable again, which disables the calculation. Setting the editability expression is where you need ago or python until that option is exposed in the UI.
Each Switch --> has a value expression set to return the default value
Each Switch --> has an editability expression that by virtue of being true disables the value expression.
Now it can "be" null, but never stay null. So long as the switch has a value... on/off or true/false or 1/0 for example, then it behaves like a normal switch. If it gets hidden it becomes null. If it gets unhidden, because it is null it will calculate to false (or your default of choice), but now it has a value, so the calculation no longer applies... until it becomes null again for whatever reason... then it calculates again... and so on.
This is now a special kind of "dynamic default value"... one that if nulled comes back. In this case it is just a simple switch but it can be for any field or complexity.
Thanks @JustinReynolds ,
My form is already loaded with so many calculated fields (tree censuses are really complex), so the idea of adding additional constraints it's a no-go for me. Thank you anyway for trying to help me.
I wonder if the guys at FieldMaps are thinking about a solution to this behavior. That could be setting the field values to the declared default for the field but not Null!
Milton
I've updated my response a bit as it is a bit simpler now that I thought about it. Still it would add 1 value expression and 1 editability expression for each switch.
I'm assuming a default of 0, could be anything
//Return this default value in case I get nulled
return 0
Each switch would have a new visibility expression (not assigned to any field in the UI)... it will get assigned to an editability expression in ago assistant.
// constraint_edt_cond_if_not_null
var mySwitch = $feature["switch_field_name"];
if (!IsEmpty(mySwitch))) {
// I have a value, let me be a controllable switch
console('Make Field Editiable, prevent valueExpression execution');
return True;
} else {
// I'm null, allow me to calculate my default value/ set my switch state
console('Make field not editiable, allow valueExpression execution');
return False;
};
Hey @JustinReynolds ,
Thank you for sharing this piece of code. It might work with those fields where I can set a default value but then, there are other fields with old measurements that are lost forever. For example, tree height last year is lost when hiding the field and so other fields. It doesn't matter if the field is marked read only.
So the switch input type and conditional visibility is useless when there is read-only data for reference, because it will be lost if you make those field hidden.
Milton
you can give the "$originalFeature" variable type a try to help with this. you might be able to get the previous state of the field and reassign it.
Also, perhaps a helper field that you keep visible at the bottom of your form that has a calculation that only executes with the state of any switch is toggled and stores a dict representation of the state of your form. If the a switch is turned on and hides fields it records the previous values of each field that is subsequently hidden... if that switch then turns back off those values could be used by calculations on your other fields to restore their values. I have not tried this, but seems sound in theory.
Hey @JustinReynolds ,
Thank you for your effort to help me on this. Your idea might work but unfortunately my project needs changing fields (adding, deleting, updating others) so, having scripts to store the state of my field seems overkill in this stage. I up-voted the idea to keep values when hiding things on FieldMaps. Maybe they can developed a "Switch" to allow to keep values or set them blank.
Saludos,
Milton
@MiltonSolano
Can you elaborate on how you set your default values for the switches? I don't seem to have these switch issues as long as I define the default in the feature template. Also, another easy thing you can try is to put each switch in a group and put the vis condition on the group instead of the field.
This is iPad Mini on v22.3.0. Nothing special going on with the switches, defaults assign on feature template and a vis condition on the yield calc switch.
I defined default value of "-", for example, when creating the feature class. I knew how to define the feature template on the classic map viewer but on the new map viewer, I can't find where to define feature templates.
I noticed on your gif, that after hidding the field, the switch shows fine. On my case, the switch disappears and is replaced by a listbox with the two options.
I'm using Android for testing.
Milton
Quick question: do you know how to define the feature template for related tables? I think I found why my smart form is changing the switch presentation:
The switches for the hosted feature classes are always presented fine because I defined the feature templates for them. But the switches on the related tables are replaced by standard list boxes because there's no feature template defined for them. How can I do this? Are you aware of this behavior?
Thanks for your help!
Milton