smocks
smocks copied to clipboard
How to use actions with global plugin?
Example from documentation, i just change smocks.route to smocks.plugin:
smocks.plugin({
// ...
input: {
yourPhoneNumber: {
label: 'What is your phone number?',
type: 'text',
defaultValue: '999.867.5309'
}
},
// now define our action for the previous route
actions: {
'the_action_id': {
label: 'the button label',
input: {
yourName: {
label: 'What is your name?',
type: 'text',
defaultValue: 'John Doe'
}
},
handler: function(config) {
// this is how you access action specific user input
var yourName = config.yourName;
// this is how you access user input created for the route
var phoneNumber = this.input('yourPhoneNumber');
// now I would perform whatever action needs to be taken
// I would make changes to "state" most likely (more about state later)
}
}
}
})
Message on page /_admin : "There are no global actions"
And this mistake in documentation:
actions: {
'the_action_id': {
},
handler: ...
}
Place handler inside the_action_id.
currently smocks does not support actions inside a global plugin
although it's a good idea