Last active
August 29, 2015 14:22
-
-
Save ivan-leschinsky/dcecf75037a4a41cbb0c to your computer and use it in GitHub Desktop.
Masked input helper for simple_form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Requires http://digitalbush.com/projects/masked-input-plugin | |
element = $('[data-behaviour=masked-input]') | |
element.mask(element.data('mask')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MaskedInput < SimpleForm::Inputs::Base | |
# Generates masked input with the desired mask | |
# | |
# Params: | |
# | |
# mask - mask that will be tranfered to the masked input java script library, decimal mask used by default | |
# | |
# Examples: | |
# | |
# = f.input :multiplier, as: :masked, mask: '?9.3' | |
# | |
# <input class="form-control" data-behaviour="masked-input" data-mask="?9.9" | |
# id="model_multiplier" name="model[multiplier]" | |
# step="any" type="string" value="1.0" data-components-host="true"> | |
# | |
def input(wrapper_options) | |
options = { | |
class: 'form-control', | |
type: :string, | |
data: { | |
behaviour: 'masked-input', | |
mask: input_options[:mask] || '?9.9' | |
} | |
} | |
options[:value] = input_options[:value] if input_options[:value].present? | |
@builder.input_field(attribute_name, options) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires Masked Input js library