2

I am creating a form for an entity that needs to have some fields omitted when creating the entity, compared to when editing it. How do I do this? Should I have one form and omit the fields when building a form for create? Or is there a another way?

e.g.

module.exports = {
    view: function(vnode){
      // form built here
    }
}
user3791372
  • 4,445
  • 6
  • 44
  • 78

1 Answers1

5

I'd have the form component check for a truthy property on vnode.attrs, maybe vnode.attrs.editing.

Then whenever you're using the component your higher-level components that are including it can do m(Form, { editing : true / false }) and the form will do the right thing.

Checking the URL seems really brittle, I wouldn't recommend building that sort of logic inside a component. That belongs in a route-handler or a page-level component.

Tivac
  • 2,553
  • 18
  • 21
  • This is actually exactly what I did whilst waiting for an answer! I didn't know whether it was kosher to use `vnode.attrs` for such a reason but it solved the problem! Thanks! – user3791372 Oct 22 '17 at 07:16