Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Display error when updating smart field #204

Open
garcia-marco opened this issue Mar 26, 2019 · 0 comments
Open

Display error when updating smart field #204

garcia-marco opened this issue Mar 26, 2019 · 0 comments

Comments

@garcia-marco
Copy link

garcia-marco commented Mar 26, 2019

Hello,
I have an object with a time slot :

{
   start: 00:00,
   end: 00:00
}

and I want my user to modify it with a smart field,
cause I want them to only be able to set time as HH:mm
So if they enter something else I want to display an error.
But I can't seem to find a solution for this, is this even possible ?
Thanks in advance.

PS :
Here's my smart field

{
 field: 'modify_delivery_time',
 type: 'String',
 get: function (order) {
  const slot = order.delivery_time ? JSON.parse(order.delivery_time) : false
  return slot ? `${slot.start} - ${slot.end}` : false
 },
 set: async function (order, slot) {
  const times = slot.replace(/\s/g, '').split("-")
  for (let i = 0; i < times.length; i++) {
   if (!moment(times[i], 'HH:mm', true).isValid()) {
    // Display error
   }
  }
  order.delivery_time = JSON.stringify({ start: times[0], end: times[1] })
  return order
 }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant