Coder Social home page Coder Social logo

mariomka / vue-checkbox-radio Goto Github PK

View Code? Open in Web Editor NEW
103.0 9.0 23.0 426 KB

Checkbox and radio component for Vue.js

Home Page: https://mariomka.github.io/vue-checkbox-radio/

License: MIT License

Vue 88.12% JavaScript 11.88%
checkbox radio vue switcher

vue-checkbox-radio's Issues

event change

May be you can add change event ? Because sometimes you need do anything else.

2 sets of radio buttons doesn't work.

I have two sets of radio buttons, only 1 of the sets work. The other set just don't seem to be responding when ticking their boxes but the binding of the model works somehow.

Allow boolean values

Using boolean values in radios currently yields a warning "Expected String, got Boolean".

It does work, but I think it'd be nice if the warning would be gone.

Use case: Building a switch with two radios.

<radio :value="true" v-model="doThing" checked>Do the thing</radio>
<radio :value="false" v-model="doThing">Don't do the thing</radio>

(Yes, one could do this with a checkbox that's checked/unchecked, but that's not always practical depending on the labels used or when one wants the user to make a conscious decision to click something).

Input focus event

I miss the @focus="$emit('focus', name)" on the input element.
So i can target the @Focus event on the custom component.

Radio groups: how can I know which of the radios was selected?

I have something like this:

screenshot_2

And this code:

<radio name="deal-type" @input="changeDealType(checked)">
    {{ dealType.description }}
</radio>

Is there any way I can tell which of the radios on my radio group was checked? For all I can tell the @input emitted event only allows me to bring checked/unchecked status for this particular radio button, but I can't tell apart which one was clicked.

Nested checkbox

I put the checkbox component inside another component and i try to do a v-model on the last one but when i do, the value is always going to be the last checkbox checked even if i make my property an array.

in the other component:

<checkbox ref="checkbox" @input="updateInput()" :value="id"></checkbox>
...
updateInput () {
  let val = this.$refs.checkbox.value
  this.$emit('input', val)
}

And in my other file who calls the component:

<my-component v-model="checkboxValues.items" id="24"/>
...
checkboxValue: {
  items: []
}

Some future requests

Thank you for this nice component! Very simple and useful.
But during working with it, I've found some things I'd like to see later:

  1. Please, add slot supporting to the '.input-box' element.
    For example, to include svg icon via 'use x-link'.
  2. Sometimes we need to add a custom class name to the '.checkbox-component' element (parent tag), not only to the nested 'input'.
    Thanks again!

why not use '==' in the return code in state()?

vue-checkbox-radio/src/components/Radio.vue

            state() {
                if (this.modelValue === undefined) {
                    return this.checked;
                }
                return this.modelValue === this.value;
            }
        },

In my project, the modelValue sometimes is INT type, and here the state() will return false :(

so, why not use '==' in the return code in state()?

When we do not specify value attribute, an empty string is sent to a server

When we use a plain checkbox element, we do not need to explicitly provide a value attribute. When checkbox is checked, a "on" value is sent to the server on form submit.

For this component, the value attribute must be specified, otherwise internally the component provides its <input type="checkbox"> with an empty value attribute. And therefore, when checkbox is checked, an empty value is sent to a server on form submit.

I spent a lot of time figuring out what's wrong.

I think that if no value specified for the component from outside, the component shouldn't add the value attribute to the internal <input type="checkbox"> element at all. In this case, browser will sent "on" to the server natively.

checkbox doesn't work

{{option.textvalue}}
			<template v-else>
				<checkbox 
				:name="item.name"
				:value="option.value"
				v-model="item.value"
				>
				   {{option.textvalue}}
				</checkbox>
			</template>
			</label>
		</div>

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.