Code Monkey home page Code Monkey logo

Comments (5)

carlosantoniodasilva avatar carlosantoniodasilva commented on May 14, 2024

SimpleForm uses the validators API to see if the attribute is required or not, you just need to add a presence validation tor your model.
There is also a config which lets you define if all fields are required by default or not, that is used only if the model does not have validations included (which, btw, is true by default): http://github.com/plataformatec/simple_form/blob/master/lib/generators/simple_form/templates/simple_form.rb#L33

from simple_form.

sher avatar sher commented on May 14, 2024

Does this depend on Rails version you are using?
On Rails 2.3 you need to install "validations_reflection" plugin in order to get "*" marks prepended automatically on attribute's label which is required (validates_presence_of :attribute).
On Rails 3 you only have to set required in the model - :presence => true
Correct me if I am mistaken.

from simple_form.

carlosantoniodasilva avatar carlosantoniodasilva commented on May 14, 2024

Yup, the validators API exists only in Rails 3.
SimpleForm for Rails 2.x does not rely on validations_reflection plugin, which means it does not reflect the validations from your model to your forms. By default all attributes will be required unless you say no.

from simple_form.

machetico avatar machetico commented on May 14, 2024

Thanks to all repliers. I am using rails 3 and it works as tundrax say. However I disagree with Carlos because if I do not use validators all attributes on the form come without the start(*). So I believe the default is "not required". This is not a big issue for me because now I use the validators and love the way it works.

from simple_form.

carlosantoniodasilva avatar carlosantoniodasilva commented on May 14, 2024

Yes you're right, I meant to say that in SimpleForm for Rails 2.x, all attributes are considered required unless you say they are not. SimpleForm for Rails 3 relies on the validators, so if no validator exist for an attribute, it's not required. It'll just consider all attributes required in a form, if that form has an object that doesn't have the validators.
I'm closing this issue so.

from simple_form.

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.