I'm trying to use a Jason field inside Commerce attached to an order, and I was running into a situation where the field would not appear in the UI when reviewing an order, but it would appear when I tried to "Edit" the Order.
Took me a long time to figure out what was going on.
Turns out that unlike the content parts Craft, Commerce has kind of a "preview screen" when first reviewing the contents of an order so that admins don't accidentally change things without intentionally meaning to. This also applies to reviewing Drafts of non-Commerce entries as well.
Craft calls the getInputHtml() function when it needs to display a field that is ready to accept user input, but not when it wants to display the read only contents of a field.
This is a relatively trivial function to implement since Jason already has the functionality to display a field as read-only.
So for the most part, it's a straight-up duplication of getInputHtml() with a couple of namespace changes with forced settings on readonly and allowRawEditing
The above could absolutely be refactored so that you don't have as much duplication between the two functions, but this would be a great addition as-is in the meantime.
I'm trying to use a Jason field inside Commerce attached to an order, and I was running into a situation where the field would not appear in the UI when reviewing an order, but it would appear when I tried to "Edit" the Order.
Took me a long time to figure out what was going on.
Turns out that unlike the content parts Craft, Commerce has kind of a "preview screen" when first reviewing the contents of an order so that admins don't accidentally change things without intentionally meaning to. This also applies to reviewing Drafts of non-Commerce entries as well.
Craft calls the
getInputHtml()
function when it needs to display a field that is ready to accept user input, but not when it wants to display the read only contents of a field.When it wants the read only version it calls the
getStaticHtml()
function associated with each field - https://docs.craftcms.com/api/v3/craft-fields-baserelationfield.html#public-methodsThis is a relatively trivial function to implement since Jason already has the functionality to display a field as read-only.
So for the most part, it's a straight-up duplication of
getInputHtml()
with a couple of namespace changes with forced settings onreadonly
andallowRawEditing
The above could absolutely be refactored so that you don't have as much duplication between the two functions, but this would be a great addition as-is in the meantime.