Title: Compulsory
Last modified: April 11, 2023

---

# Compulsory

 *  Resolved [stephenboluwatife1](https://wordpress.org/support/users/stephenboluwatife1/)
 * (@stephenboluwatife1)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/compulsory-2/)
 * I have two field and I want one of the two to be compulsory for example if there
   fill the first one the second one is not required again but if there don’t fill
   in both of the fields I want and there click on submit button I want it to say
   there should fill one of the two from that is compulsory

Viewing 1 replies (of 1 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/compulsory-2/#post-16644173)
 * Hello [@stephenboluwatife1](https://wordpress.org/support/users/stephenboluwatife1/)
 * If only one of the fields is required, you can make them required or not by coding.
 * I’ll try to describe the process with an example.
 * Assuming the fields’ names are fieldname1 and fieldname2:
   Insert a calculated
   field in the form to be used as an auxiliary. You can hide it by ticking a checkbox
   in its settings. And enter the following equation through its settings:
 *     ```wp-block-code
       (function () {
           var f1 = getField(fieldname1|n).jQueryRef().find(':input'),
       	f2 = getField(fieldname2|n).jQueryRef().find(':input');
   
           if (CONCATENATE(fieldname1|r, fieldname2|r) == '') {
               f1.addClass('required');
               f2.addClass('required');
           } else {
               f1.removeClass('required');
               f2.removeClass('required');
           }
       })()
       ```
   
 * Note I used the fields’ names with modifiers `|n` and `|r`. The plugin replaces
   the fields’ names with their values in the equations before evaluating them. 
   Also, the plugin tries to extract the numbers from the fields’ values to use 
   them in mathematical operations. The `|n` modifier (Like `fieldname1|n`) tells
   the plugin you want to use the field’s name instead of its value. And the `|r`
   modifier (`fieldname1|r`) allows you to use the field’s raw value instead of 
   the preprocessed one.
 * Best regards.

Viewing 1 replies (of 1 total)

The topic ‘Compulsory’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [codepeople](https://wordpress.org/support/users/codepeople/)
 * Last activity: [3 years, 2 months ago](https://wordpress.org/support/topic/compulsory-2/#post-16644173)
 * Status: resolved