AutoForm: disable whole Object from schema


#1

So my schema is something like

OrdersCollection.attachSchema(new SimpleSchema({
	status: {
		type: Object,
	},
	"status.phase": {
		type: String,
	},
	"status.locked": {
		type: Boolean,
	},
	details: {
		type: Object,
	},
	"details.startTime": {
		type: Date,
	},
	"details.endTime": {
		type: Date,
	},
	"details.location": {
		type: String,
	},
}));

I would like to if (status.locked) { disable details Object }. So basically make the Details Object readonly, but keep the status object functional.

Is there a better way than to specify autoform: { disabled: true } for each input element?


#2

Good question! Have you been able to figure out a good solution?
autoValue could be used for enforcing your constraint, but it would not translate into any autoform UI representation. But I think you can use the disabled attribute when displaying those form fields, something like:

{{>afQuickField name='details.startTime' disabled=doc.statusLocked}}

(With statusLocked being defined as a collection helper on the OrdersCollection, since we can’t do nested expressions in spacebars yet.)


#3

I’m afraid I haven’t found a solution. What you suggest is what I ended up using: putting the disabled loginc into the template. This feels kind of unmeteoric and requires lots of hand labor, so currently I’m thinking about ditching autoform and figuring out a simpler form package on my own.


#4

unfortunately, there really isn’t a good way to do this.

I think the best chance is to extend the options of denyUpdate or denyInsert to take a function as a parameter which returns a Boolean and submit a PR to collection2.