Coder Social home page Coder Social logo

How work with Checkbox Widget? about form HOT 5 CLOSED

yiisoft avatar yiisoft commented on June 12, 2024
How work with Checkbox Widget?

from form.

Comments (5)

samdark avatar samdark commented on June 12, 2024

Would you please provide $value and corresponding model attribute values that are not correct?

from form.

Gerych1984 avatar Gerych1984 commented on June 12, 2024

Would you please provide $value and corresponding model attribute values that are not correct?

I think checkbox widget work fine - it generated input with current value of FormModel, like others inputs.

But I also think - need return boolean widget, that generated checkbox with static attribute value = 1 and optional hidden input with value 0

from form.

terabytesoftw avatar terabytesoftw commented on June 12, 2024

¿Podría proporcionar los valores de atributo del modelo correspondientes que no sean correctos?$value

Creo que el widget de casilla de verificación funciona bien: generó entrada con el valor actual de FormModel, al igual que otras entradas.

Pero también creo que necesita un widget booleano de retorno, que generó una casilla de verificación con valor de atributo estático = 1 y entrada oculta opcional con valor 0

case 'bool':

Test Bool CheckBox:

// value bool false

As you can see there is a test suite for all possible values.

Could you show the code of your widget?

from form.

terabytesoftw avatar terabytesoftw commented on June 12, 2024

I think I understood your problem, checkbox always returns a value 0 or 1, it does not return boolean, if you want to save to your data, as a boolean value you just have to cast (bool), checking the previous behavior of BooleanInput::class the same

private function getBooleanValue(): bool
with the difference that it converts the value cast bool, which you can do in the form, and thus maintain a uniform behavior.

from form.

Gerych1984 avatar Gerych1984 commented on June 12, 2024

I think I understood your problem, checkbox always returns a value 0 or 1, it does not return boolean, if you want to save to your data, as a boolean value you just have to cast (bool), checking the previous behavior of BooleanInput::class the same

private function getBooleanValue(): bool

with the difference that it converts the value cast bool, which you can do in the form, and thus maintain a uniform behavior.

No, problem is not in type cast. See - i write stand alone view file with simple model and form. Check Is active, send form and you will see result
test.zip

from 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.