<p>I want to make a craft commerce custom order field required (server side). I already use this for require the default address fields. But how to add custom fields? Because this is done on the Address class.</p>
<pre><code>        /**
         * Server require custom order fields
         */
        Event::on(
          Address::class,
          Model::EVENT_DEFINE_RULES,
          function(DefineRulesEvent $event) {
              $rules = $event-&gt;rules;
              $rules[] = [['firstName', 'lastName'], 'required'];
              $rules[] = ['field:fieldHandle', 'required']; // &lt;- this is not working
              $event-&gt;rules = $rules;
          }
        );
</code></pre>

CC BY-SA 4.0
2023-01-25T12:09:29.527Z
I'm surprised that the update cart method in Commerce doesn't seem to respect the required lightswitch of an order field. This seems like a bug to me - I don't think you should have to use a custom module to do it.
James Smith
CC BY-SA 4.0
2023-01-26T14:09:21.960Z
But is it possible with some kind of event? I tried making the field required but that's not working. I also think this should work but because it doesn't I'm looking for an alternative also because I work with a onepagecheckout with ajax calls
Maarten Heideman
CC BY-SA 4.0
2023-01-26T14:13:33.490Z
I'm not sure, but I'd probably raise this as a bug report with Craft Commerce, as it doesn't seem right that you are able to mark an order field as "required" but that choice is not respected.
James Smith
<craft3><plugin-craftcommerce><custom-field><required>
How make custom order fields required with "event_define_rules" like a required address fields?
# How make custom order fields required with "event_define_rules" like a required address fields?

(Asked by: username_0 on 2023-01-24)

I want to make a craft commerce custom order field required (server side). I already use this for require the default address fields. But how to add custom fields? Because this is done on the Address class.
        /**
         * Server require custom order fields
         */
        Event::on(
          Address::class,
          Model::EVENT_DEFINE_RULES,
          function(DefineRulesEvent $event) {
              $rules = $event->rules;
              $rules[] = [['firstName', 'lastName'], 'required'];
              $rules[] = ['field:fieldHandle', 'required']; // <- this is not working
              $event->rules = $rules;
          }
        );

**Tags:** craft3, plugin-craftcommerce, custom-field, required
> **Comments:**
> **username_1**: I'm surprised that the update cart method in Commerce doesn't seem to respect the required lightswitch of an order field. This seems like a bug to me - I don't think you should have to use a custom module to do it.  
> **username_0**: But is it possible with some kind of event? I tried making the field required but that's not working. I also think this should work but because it doesn't I'm looking for an alternative also because I work with a onepagecheckout with ajax calls  
> **username_1**: I'm not sure, but I'd probably raise this as a bug report with Craft Commerce, as it doesn't seem right that you are able to mark an order field as "required" but that choice is not respected.  

---

## 0 answers

