How to check if managed_file has uploaded a video and use it in states I want to disable the submit button in a form for as long as there are no value/uploaded video in a managed_file but I can't seem to find what form name or element property I have to check for in #states.
I have the following:
$form['file'] = [
  '#type' =&gt; 'managed_file',
  '#title' =&gt; t('File'),
  '#description' =&gt; $this-&gt;t('Choose video to upload.'),
  '#upload_validators' =&gt; $validators,
];
$form[&quot;submit&quot;] = [
  &quot;#type&quot; =&gt; &quot;submit&quot;,
  &quot;#value&quot; =&gt; t('Submit'),
  '#states' =&gt; [
    'enabled' =&gt; [
      ':input[name=&quot;file&quot;]' =&gt; ['empty' =&gt; FALSE],
    ],
  ],
];

I've also tried using value =&gt; true, :input[name=&quot;files[0] and :input[name=&quot;files[file] without luck. How can I enable the submit button when file has been processed?
If you examine the comments in the documentation, there are several things to look out for:

You may need to target the element's widget, as mentioned in this comment. Most likely you would do this in a #process callback or in a form alter hook.


This is a good nuance to understand - thanks! Targeting the widget
worked for me on a number field. It gets ignored otherwise.

// My number field is hidden unless repeat is selected
$form['field_myfield_num']['#states'] = [
  'visible' =&gt; [
    ':input[name=&quot;field_myfield_select&quot;]' =&gt; ['value' =&gt; (string) 'repeat'],
    ],
];

// My number field is set as required when repeat is selected.
$form['field_myfield_num']['widget']['0']['value']['#states'] = [
  'required' =&gt; [
    ':input[name=&quot;field_myfield_select&quot;]' =&gt; ['value' =&gt;  (string) 'repeat'],
  ],
];


In the same comment above, we also see that sometimes it helps to cast your candidate value to a string: ['value' =&gt;  (string) 'repeat']. I've also seen this explicitly mentioned elsewhere, but can't find the reference.

It is possible to test for a negation using '!value', as seen in this comment:



I had a form with a field of #type select_or_other, which renders like
radios. I wanted to enable the submit button when the form element was
not &quot;none&quot;. The following worked for me:

$form['actions']['submit'] = [
  '#type' =&gt; 'submit',
  '#value' =&gt; $this-&gt;t('Donate'),
  '#button_type' =&gt; 'primary',
  '#states' =&gt; [
    'enabled' =&gt; [
      ':input[name=&quot;amount[select]&quot;]' =&gt; ['!value' =&gt; 'none'],
    ],
  ],