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.

v-bind="$attrs" and problems with "value" attribute for multi-checkboxes

See original GitHub issue

Version

2.5.16

Reproduction link

https://codepen.io/anon/pen/aYqoYL?editors=1010

Steps to reproduce

  • Check the checkbox
  • See that the value is set to “null” even though the input element has its value (correctly) set to “foo”

What is expected?

  • The value passed through “$attrs” should be the checkbox’s value used

(or, the value never hits the DOM element, the fact that it is present on the DOM element but isn’t used in the model is a conflict IMO)

What is actually happening?

  • Null is set

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

2reactions
emanuelmutschlechnercommented, Apr 16, 2018

I get your point, but I’m not sure if this is a bug or not. We need some feedback from the core team.

My solution is partly based on this example code, where value is bound explicit and used with disabled attribute inheritance. source

Vue.component('base-input', {
  inheritAttrs: false,
  props: ['label', 'value'],
  computed: {
    inputListeners: function () {
      var vm = this
      // `Object.assign` merges objects together to form a new object
      return Object.assign({},
        // We add all the listeners from the parent
        this.$listeners,
        // Then we can add custom listeners or override the
        // behavior of some listeners.
        {
          // This ensures that the component works with v-model
          input: function (event) {
            vm.$emit('input', event.target.value)
          }
        }
      )
    }
  },
  template: `
    <label>
      {{ label }}
      <input
        v-bind="$attrs"
        v-bind:value="value"
        v-on="inputListeners"
      >
    </label>
  `
})
1reaction
pearofduckscommented, Apr 16, 2018

@emanuelmutschlechner - please read my previous response. With $attrs this shouldn’t be necessary. I’m pretty confident this is a valid bug, but I appreciate you trying to help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why do we need the value attribute for checkbox inputs? - HTML
So the short answer is; no, it wouldn't cause a problem if there are multiple checkboxes with the same name value, and in...
Read more >
Required attribute on multiple checkboxes with the same name?
i had the same problem, my solution was apply the required attribute to all elements <input type="checkbox" name="checkin_days[]" ...
Read more >
Class Laminas\Form\Element\MultiCheckbox
Methods ; setAttributes(), Set many attributes at once, Element ; setChecked(), Checks or unchecks the checkbox. Checkbox ; setCheckedValue(), Set the value to...
Read more >
Attribute selectors - CSS: Cascading Style Sheets | MDN
Represents elements with an attribute name of attr whose value is a whitespace-separated list of words, one of which is exactly value.
Read more >
HTML | value Attribute - GeeksforGeeks
Difficulty Level : Basic; Last Updated : 30 Nov, 2021 ... The value attribute in HTML is used to specify the value 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