Giter VIP home page Giter VIP logo

Comments (4)

adis-me avatar adis-me commented on August 19, 2024

Hmm perhaps I solved it by extending, is this correct to use:

@(field: play.api.data.Field, args: (Symbol,Any)*)(implicit handler: b3.B3FieldConstructor)
@b3.inputFormGroup(field, withFeedback = false, withLabelFor = true, b3.Args.withDefault(args, 'class -> "")) { fieldInfo =>
    <div class="checkbox">
        <label for="@fieldInfo.id">
        <input type="checkbox" id="@fieldInfo.id" name="@fieldInfo.name" @if(fieldInfo.value == Some("true")){ checked } @toHtmlArgs(fieldInfo.innerArgsMap)>
        </label>
    </div>
}

from play-bootstrap.

adrianhurt avatar adrianhurt commented on August 19, 2024

Sorry, but I don't understand your question. A checkbox will work with value="true" as default, and a radio uses a Seq[(String, Any)], so you could use simply something like Seq("true"->"True","false"->"False").

Play will handle the true and false strings as the corresponding boolean.

Then, the following code

@b3.checkbox( form("foo"), '_text -> "Remember me" )
@b3.radio( form("foo"), options = Seq("true"->"True","false"->"False"), '_label -> "Radio Group" )

will be rendered as:

<div class="form-group" id="foo_field">
  <div class="checkbox">
    <label for="foo">
      <input type="checkbox" id="foo" name="foo" value="true">
      Remember me
    </label>
  </div>
</div>

<div class="form-group" id="foo_field">
  <label class="control-label ">Radio Group</label>
  <div class="radio">       
    <label class="" for="foo_true">
      <input type="radio" id="foo_true" name="foo" value="true">
      True
    </label>
  </div>
  <div class="radio">       
    <label class="" for="foo_false">
      <input type="radio" id="foo_false" name="foo" value="false">
      False
    </label>
  </div>
</div>

from play-bootstrap.

adis-me avatar adis-me commented on August 19, 2024

@adrianhurt Yes it works like you described. I did not know that Seq("true"->"True","false"->"False") will work because of the signature Seq[(String, Any)].

I tried the following but that did not worked for radio inputs: Seq("1"->"True","0"->"False").

I will close this issue since the real problem is my Scala knowledge 😆

from play-bootstrap.

adrianhurt avatar adrianhurt commented on August 19, 2024

Don't worry ;) And yes, I think you had a little confusion but not with Scala. Note that everything will be finally rendered as a simple String for HTML. That's the reason to use (String, Any) values (where any Any value will call its toString function.

from play-bootstrap.

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.