rubyvoltrb

how to add validation messages in volt?


The volt docs refer to "client side validation" but there is no example code for this.

I have volt-fields set up with a validation like this:

validate :description, length: { minimum: 1, maximum: 1000 }

then in my controller:

buffer.save!.then do |record|
  # javascript breakpoint here
end.fail do |err|
  # javascript breakpoint here
end

When I submit an object with an empty description, the then block is called. I would have expected the fail block to be called. Furthermore, I can't get access to the errors, if any are being added at all.

I've tried both record.errors and record.server_errors - both are empty as far as I can tell.

Do I need to write a custom validator, or can I use this built-in approach?


Solution

  • I asked about this and the feature is basically incomplete. Since the maintainer has no time to work on the project at this stage it will not be happening until someone else takes up maintaining the Volt framework.