question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unchecked checkbox show up as checked

See original GitHub issue

I have the following schema for checkbox:

{
type: "checkbox",
label: "Terms and Conditions",
model: "terms",
default: false
}

When I save the form, it posts the string “false” to the server.

So when the data is read from the server and the response is assigned to the model (ex. when editing an existing form), the component interprets “false” as truthy (strings are truthy) and makes the checkbox ticked.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
hansi90commented, Oct 12, 2017

You can define a “get” method in schema, where you can convert the model value.

{
    type: "checkbox",
    label: "Checkbox",
    model: "status",
    inputName :"checkname",
    get(model) {
        if (model){
            if (isString(model.status))
                return model.status === "true" ? true : false;
            
            return model.status;
        }
    }
}
0reactions
lionel-bijaouicommented, Jun 28, 2018

@sjordan1975 You are welcome to implement the result of your philosophical software design/development discussion into a PR. In the meantime, I’m closing this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

check / uncheck checkbox using jquery? - Stack Overflow
An element is considered checked as long as it has the attribute of checked even if it has no value or the value...
Read more >
How do I check/uncheck a checkbox input or radio button?
You can check or uncheck a checkbox element or a radio button using the .prop() method: 1. 2. 3. 4. 5. // Check...
Read more >
How to Check/Uncheck CheckBoxes in a Page using jQuery ...
Today, I'll show you how to check or uncheck a particular checkbox using jQuery, one of the most popular JavaScript frameworks. jQuery provides...
Read more >
How to Check or Uncheck A Checkbox Dynamically Using ...
Answer: Use the jQuery prop() method. You can use the jQuery prop() method to check or uncheck a checkbox dynamically such as on...
Read more >
JavaScript Checkbox
A checkbox has two states: checked and unchecked. ... select one or more checkboxes and click the button, it'll show the values of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found