Validated Field Items

Sometimes you want data to be entered in a certain format. For example in the Cambridge application the supply_point id seems to be entered in a format like “CAM-132776-SP”. To enforce data consistency and enhance data quality you would like to validate the correct string format during data entry.
These are the steps:

  • 1) Create a value_manager that will validate the input.
def_slotted_exemplar( :supply_point_id_value_manager,
                      {},
              :field_item_value_manager)
$

_pragma(classify_level=restricted)
_method supply_point_id_value_manager.validate(p_value)
    ##
    ## Validate that the string is in the format of
    ## CAM-909141-SP. First three characters, then 6 digits ended
    ## with SP.
    _super.validate(p_value)

    _if p_value _is _unset _then _return _endif 

    _local ok? << _self.is_valid?(p_value)

    _if _not ok?
    _then     
        condition.raise(:supply_point_id_format_error, :string, p_value)
    _endif 
_endmethod
$
  • 2) Create a field_editor that uses the value_manager.
_pragma(classify_level=restricted)
## Special field editor for entering the id of a supply_point.
def_slotted_exemplar( :supply_point_id_field_editor,
                      {},
              :in_place_alpha_field_editor)
$

_pragma(classify_level=restricted,usage={subclassable})
_private _method supply_point_id_field_editor.set_manager()
    ## 
    ## Set the value manager to supply_point_id_value_manager.
    _self.manager << supply_point_id_value_manager.new( :field_item, _self.field_item )
_endmethod
$
  • 3) Publish the field_editor so it becomes available in the ACE editors.
editor_manager.register_field_editor(
                      :supply_point_id_field_editor,
                      _unset, { :alpha_field } )
$
  • 4) Assign the field_editor to the supply_point ID field in the ACE object property editor.
object%20property%20editor.png
  • 5) Test it!
supply_point%20error%20on%20id.png
enjoy the quality boost!
I have attached the example sourcefiles for more detail information:
supply_point_id_field_editor.magik and supply_point_id_value_manager.magik
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License