GithubHelp home page GithubHelp logo

Checked values are empty about active_enum HOT 17 CLOSED

adzap avatar adzap commented on June 9, 2024
Checked values are empty

from active_enum.

Comments (17)

adzap avatar adzap commented on June 9, 2024

Can you please provide the code for enum definition, model enumeration (if enum
not defined in the model), and the view select code.

On 26/09/12 2:52 PM, Kurakin Alexander wrote:

It seems |select|'s |checked| value isn't set currently. Yeah, Rails checks
|model.color| and gets |red| but not |1|. But db's values is |1| instead. Oops,
checked value is wrong, that why current value of select box is blank, amn't I
right?


Reply to this email directly or view it on GitHub
#17.

from active_enum.

adzap avatar adzap commented on June 9, 2024

Do you have

require 'active_enum/form_helpers/formtastic2' 

in the initializer?

from active_enum.

adzap avatar adzap commented on June 9, 2024

If so, please try and add a failing spec here

https://github.com/adzap/active_enum/blob/master/spec/active_enum/form_helpers/formtastic2_spec.rb

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap Yes, I have. I'll try.

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap sorry, formtastic isn't important here. Test fails with all forms.

from active_enum.

adzap avatar adzap commented on June 9, 2024

@kuraga the problem is you are assigning a string value to sex attribute. You must assign a symbol value for the gem to intercept and convert it to the enum integer value.

from active_enum.

adzap avatar adzap commented on June 9, 2024

@kuraga a shortcut to get the enum class for an attribute is

record.sex(:enum)

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap Yes, you're right, 05bd57f. But real forms don't work right. I've created an app to demonstrate, visit /people please, edit sex and edit one more time please. https://github.com/kuraga/app_for_active_enum_issue_17

from active_enum.

adzap avatar adzap commented on June 9, 2024

I see the problem. You have the use_name_as_value config option set. This means if you use the field in a form select it is trying to match 'Male' to 1 in the select options. Play with it in the console and you can see what @person.sex will return a string value. You can't use the to_select form on the enum options in the select if you have this option set.

Why did want to use this option? Was just to display in the show action?

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap I know all of that. I wrote this explanation in previous issue #16. In this issue I just wanted to formalize it (and verify by together). Yes, just to display in show action without some specific parameters

I just think it's an issue to think about in next versions. Because maybe it's a strange behavior (form without selected value by default). Ok, what about to change behavior for formtastic and simple_form situation, at least? I just propose to think about it later.

And your gem is very good to contribute for me because my experience isn't too long :-). But my ideas are strange, may be... Thanks very much.

from active_enum.

adzap avatar adzap commented on June 9, 2024

Well, didn't actually. The vital fact of the use_name_as_value config setting was never mentioned. There is no problem with the gem as I see it, only the possible addition of a warning.

What change to formastic or simple_firm do you mean?

On 01/10/2012, at 6:15 PM, Kurakin Alexander [email protected] wrote:

@adzap I know all of that. I wrote this explanation in previous issue #16. In this issue I just wanted to formalize it (and verify by together). Yes, just to display in show action without some specific parameters

I just think it's an issue to think about in next versions. Because it's a strange behavior. Ok, about what about to change behavior for formtastic and simple_form situation, at least? I just propose to think about it later.

And your gem is very good to contribute for me because my experience isn't too long :-). But my ideas are strange, may be... Thanks very much.


Reply to this email directly or view it on GitHub.

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

Yes, I wasn't right. I should use String id instead of Fixnum... Sorry.

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

Ok, let's begin again :)

There is a form. It seems select's checked value isn't set currently. Yeah, Rails checks model.color and gets red but not 1. But db's values is 1 instead. Oops, checked value is wrong, that why current value of select box is blank, amn't I right?

But if we set id==value (i.e. red), it's all good here. red value is checked. I can modify test that I've wrote above to show it... Thanks.

P.S. The problem is we can't use Strings, see #21. If we set id==value==1, problems with i18n will be...

from active_enum.

adzap avatar adzap commented on June 9, 2024

This is not the problem. You are confusing the use_name_as_value concept, and the use case for having string ids at all. Turn off use_name_as_value and use model.color(:name) where you need it.

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap You're right. But if use_name_as_value==false then model.color isn't translated. Just there are two situations the are not possible simultaneously (yes?): 1) puts model.color is translated; 2) in form, select's checked value is right.

from active_enum.

adzap avatar adzap commented on June 9, 2024

puts model.color(:name) is what you want.

selects will work as normal with use_name_as_value = false. You can't get both an id and translated name from model.color, end of story.

from active_enum.

kuraga avatar kuraga commented on June 9, 2024

@adzap foooh. Yahoo! Yes. That's a "problem" that I'm explaining :) I think that's good to think if you will change behavior. Because if I start use active_enum I should rewrite views (model.color to model.color(:name)...

from active_enum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.