allow a proc to be given as label option #947

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
@rainchen

rainchen commented Jul 4, 2013

allow a proc to be given as label option, for example:

semantic_form_for(@new_post) do |builder|
  builder.input(:title, :label => proc{ 'My label' })
end

see details: #888

@rainchen

This comment has been minimized.

Show comment Hide comment
@rainchen

rainchen Jul 5, 2013

hmm, CI errors by:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot
continue.

how can I restart the CI jobs?

rainchen commented Jul 5, 2013

hmm, CI errors by:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot
continue.

how can I restart the CI jobs?

@justinfrench

This comment has been minimized.

Show comment Hide comment
@justinfrench

justinfrench Jul 9, 2013

Owner

@rainchen we had the same issue in the rails4 branch, we need to lock nokogiri to < 1.6 until we drop 1.8.7. You can cherry-pick that commit, or wait 'till the #946 pull request is merged in (should be pretty soon).

Owner

justinfrench commented Jul 9, 2013

@rainchen we had the same issue in the rails4 branch, we need to lock nokogiri to < 1.6 until we drop 1.8.7. You can cherry-pick that commit, or wait 'till the #946 pull request is merged in (should be pretty soon).

@justinfrench

This comment has been minimized.

Show comment Hide comment
@justinfrench

justinfrench Jul 10, 2013

Owner

@rainchen could you provide an example situation where you needed a proc?

Owner

justinfrench commented Jul 10, 2013

@rainchen could you provide an example situation where you needed a proc?

@rainchen

This comment has been minimized.

Show comment Hide comment
@rainchen

rainchen Jul 11, 2013

@justinfrench please see details: #888
in short, I used it for i18n, like: builder.input(:title, :label => proc{ I18n.t(:xx) })

@justinfrench please see details: #888
in short, I used it for i18n, like: builder.input(:title, :label => proc{ I18n.t(:xx) })

@twalpole

This comment has been minimized.

Show comment Hide comment
@twalpole

twalpole Jul 11, 2013

Collaborator

@rainchen Formtastic already has i18n support builtin for labels -- what functionality does this patch supply that isnt handled by the builtin functionality?

Collaborator

twalpole commented Jul 11, 2013

@rainchen Formtastic already has i18n support builtin for labels -- what functionality does this patch supply that isnt handled by the builtin functionality?

@rainchen

This comment has been minimized.

Show comment Hide comment
@rainchen

rainchen Jul 11, 2013

@twalpole some times you are not using the same key as the attribute for i18n, like builder.input(:title, :label => proc{ I18n.t(:title_with_special_notes) })

@twalpole some times you are not using the same key as the attribute for i18n, like builder.input(:title, :label => proc{ I18n.t(:title_with_special_notes) })

@twalpole

This comment has been minimized.

Show comment Hide comment
@twalpole

twalpole Jul 11, 2013

Collaborator

@rainchen but wouldnt
builder.input(:title, label: I18n.t(:title_with_special_notes))
do the same thing??

Collaborator

twalpole commented Jul 11, 2013

@rainchen but wouldnt
builder.input(:title, label: I18n.t(:title_with_special_notes))
do the same thing??

@rainchen

This comment has been minimized.

Show comment Hide comment
@rainchen

rainchen Jul 11, 2013

@twalpole but this is not working in ActiveAdmin, it's using some DSL methods like filter, the value of the label will be static if use filter :foo, :label => I18n.t(:foo).if you change the locale in url like /posts?locale=de, then the label won't be change to i18n with locale=de.All I have to do is using a proc like filter :foo, :label => proc { I18n.t(:foo) }.
anyway, allowing using a proc for label, will make formtastic more flexible.

@twalpole but this is not working in ActiveAdmin, it's using some DSL methods like filter, the value of the label will be static if use filter :foo, :label => I18n.t(:foo).if you change the locale in url like /posts?locale=de, then the label won't be change to i18n with locale=de.All I have to do is using a proc like filter :foo, :label => proc { I18n.t(:foo) }.
anyway, allowing using a proc for label, will make formtastic more flexible.

@amuntasim

This comment has been minimized.

Show comment Hide comment
@amuntasim

amuntasim Sep 28, 2013

imagine a situation where current_user has some impact on the label like:
:label => proc{current_user.admin? ? "hello" : "holla" }

So I agree with rainchen in this regard

imagine a situation where current_user has some impact on the label like:
:label => proc{current_user.admin? ? "hello" : "holla" }

So I agree with rainchen in this regard

@justinfrench

This comment has been minimized.

Show comment Hide comment
@justinfrench

justinfrench Apr 5, 2014

Owner

I'm going to close this sorry. I've yet to hear of a concrete example in a real-world app that would need this (that couldn't be solved with standard i18n). I agree this would make Formtastic more powerful, but not in a direction I'm thrilled about. Ideally, we'd be removing all string options (e.g. :label) from the DSL and relying purely on I18n.

Happy to have this re-opened with a compelling real-world app case that I18n can't solve (and an up-to-date patch).

Thanks for your work so far.

Owner

justinfrench commented Apr 5, 2014

I'm going to close this sorry. I've yet to hear of a concrete example in a real-world app that would need this (that couldn't be solved with standard i18n). I agree this would make Formtastic more powerful, but not in a direction I'm thrilled about. Ideally, we'd be removing all string options (e.g. :label) from the DSL and relying purely on I18n.

Happy to have this re-opened with a compelling real-world app case that I18n can't solve (and an up-to-date patch).

Thanks for your work so far.

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