meteor-cfs-autoform icon indicating copy to clipboard operation
meteor-cfs-autoform copied to clipboard

No way to make a file field mandatory

Open romaroma opened this issue 9 years ago • 2 comments

Currently it is not possible to make a file field mandatory because it has "dummyId" value and passes the form validation.

Handling formToDoc, docToForm, formToModifier hooks of AutoForm could help invalidating the form if the field is not optional.

romaroma avatar May 11 '15 16:05 romaroma

@romaroma any workaround found??

dmeneses avatar May 19 '15 12:05 dmeneses

@dmeneses no unfortunately, we currently use extra validation on the client side:

if (insertDoc[key] === 'dummyId') {
  insertDoc[key] = $('input[name=' + key + ']').attr('data-id');
  if (!insertDoc[key]) {
    isValid = false;
    // raise an autoform error
    context.addInvalidKeys([{name: key, type: 'required'}]);
  }
}

Actual value of the field is stored in data-id attribute of an extra hidden field, so we just copy it and compare with false.

romaroma avatar Jun 07 '15 18:06 romaroma