Skip to content

Instantly share code, notes, and snippets.

@bmichotte
Last active August 29, 2015 14:25
Show Gist options
  • Save bmichotte/29749f1d73d626537117 to your computer and use it in GitHub Desktop.
Save bmichotte/29749f1d73d626537117 to your computer and use it in GitHub Desktop.
class TestFormScreen < PM::FormScreen
title "PM::XLFormScreen"
form_options required: :asterisks,
# by default, button "title" is NSLocalizedString("Save")
on_save: :'save_form:',
# or
on_cancel: { action: :cancel_form, item: :cancel, title: "Cancel" }
def form_data
[
{
title: 'Account information',
footer: 'Some help text',
cells: [
{
title: 'Email',
name: :email,
type: :email,
placeholder: 'Enter your email',
required: true
},
{
title: 'Name',
name: :name,
type: :text
},
{
title: 'Yes ?',
name: 'check',
type: :switch
},
{
title: 'Options',
name: 'options',
type: :selector_push,
options: {
"value_1" => "Value 1",
"value_2" => "Value 2",
"value_3" => "Value 3",
"value_4" => "Value 4",
},
value: "value_1",
on_change: lambda {|old_value, new_value|
puts "#{old_value} has been changed to #{new_value}"
}
}
]
},
{
cells: [
{
title: 'A slider',
name: :slider,
type: :slider,
properties: {
max: 100,
min: 2,
step: 4
}
},
{
title: 'A date',
name: :date,
type: :date_inline
},
{
title: 'Another date',
name: :other_date,
type: :date_inline,
properties: {
min: NSDate.new
}
},
{
title: 'An image',
name: :picture,
type: :image
}
]
},
{
title: 'Multi-value',
name: 'multi',
options: [:insert, :delete, :reorder],
cells: [
{
title: 'Some text',
name: :some_text,
type: :text
}
]
}
]
end
def save_form(values)
mp on_save: values
end
def cancel_form
mp 'cancel_form has been called'
end
end
@jamonholmgren
Copy link

Just a "thinking out loud" idea:

class TestFormScreen < PM::FormScreen

  title "PM::XLFormScreen"

  form_options asterisk: true, on_save: :'save_form:', on_cancel: :cancel_form

  def form_data
    # ...

@bmichotte
Copy link
Author

so, it will be

class TestFormScreen < PM::FormScreen

  title "PM::XLFormScreen"

  form_options required: :asterisks, 

                     # by default, button "title" is NSLocalizedString("Save")
                     on_save: :'save_form:', 

                     # or 
                     on_cancel: { action: :cancel_form, item: :cancel, title: "Cancel" }

@bmichotte
Copy link
Author

form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment