CRM-2696 Edit Custom Fields : Erroneous form validation error occurs when saving an existing custom field - "Option Type is a required field"

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Core CiviCRM
    • Labels:
      None

      Description

      This problem occurs when there are not option groups linked to custom fields (yet). So to recreate - start with a DB that does NOT have sample data loaded. Then create a custom field type = Yes / No. Save the field, then go to edit it and try to save it again. You'll get the form validation error on the option_type field.

      NOTE: if you create a select, radio or checkbox field first - you won't see this bug.

      The cause of this is that the code goes to this condtion (Custom/Field.php):

      if ( empty( $optionGroups ) ) {
      $optionTypes = array( '1' => ts( 'Create a new set of options' ) );
      $extra = array( 'onclick' => "showOptionSelect();");
      $element =& $this->addRadio( 'option_type',
      ts('Option Type'),
      $optionTypes,
      $extra,
      '<br/>', true
      );
      $element->freeze( );

      ... and if you do a view source - the option_type field actually doesn't exist in the source (it would be hidden and frozen in any case) .

      I'm not sure what the right fix is? Maybe we need to make the presence of that "required" field conditional when in UPDATE mode - not add it to the form object when the HTML type is not checkbox, radio or mult-select.

        Attachments

          Activity

          [CRM-2696] Edit Custom Fields : Erroneous form validation error occurs when saving an existing custom field - "Option Type is a required field"
          Donald A. Lobo added a comment -


          that field should not be required since its optional. and we have other formrule checks. overall that code is quite bad and we should clean it up in 2.1

          Kiran Jagtap added a comment -

          Tested and Confirmed for 2.1 ( r - 16242 )

            People

            • Assignee:
              Kiran Jagtap
              Reporter:
              David Greenberg

              Dates

              • Created:
                Updated:
                Resolved: