class Conversation < ActiveRecord::Base
enum status: { active: 0, archived: 1 }
end
matestack_form my_form_config do
form_radio key: :status, options: Conversation.statuses
end
matestack_form my_form_config do
form_radio key: :status, [1,2,3], init: 1
end
class Components::MyFormRadio < Matestack::Ui::VueJs::Components::Form::Radio
vue_name "my-form-radio"
# optionally add some data here, which will be accessible within your Vue.js component
# Make sure to merge your custom data into super. That way you're still able to bootstrap
# your custom component with the base vue_props
def vue_props
super.merge({
foo: "bar"
})
end
def response
# exactly one root element is required since this is a Vue.js component template
div class: "your-custom-markup" do
render_options
render_errors
end
end
end
const myFormRadio = {
mixins: [MatestackUiVueJs.componentMixin, MatestackUiVueJs.formRadioMixin],
template: MatestackUiVueJs.componentHelpers.inlineTemplate,
data() {
return {};
},
methods: {
afterInitialize: function(value){
// optional: if you need to modify the initial value
// use this.setValue(xyz) in order to change the value
// this method can be used in other methods or mounted hook of this component as well!
this.setValue(xyz)
}
},
mounted: function(){
// use/initialize any third party library here
// you can access the default initial value via this.componentConfig["init_value"]
// if you need to, you can access your own component config data which added
// within the prepare method of the corresponding Ruby class
// this.componentConfig["foo"] would be "bar" in this case
}
}
export default myFormRadio
// and register in your application js file like:
appInstance.component('my-form-radio', myFormRadio) // register at appInstance
matestack_form some_form_config do
Components::MyFormRadio.call(key: :foo, options: [1,2,3])
end