Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox with vue data array does not work. #1136

Closed
JaderCM opened this issue Nov 14, 2017 · 22 comments
Closed

Checkbox with vue data array does not work. #1136

JaderCM opened this issue Nov 14, 2017 · 22 comments
Assignees
Labels

Comments

@JaderCM
Copy link

JaderCM commented Nov 14, 2017

Steps to reproduce

  1. JavaScript - Create a vue object with one property as an array;
  2. HTML - Bind at least two md-checkbox using a v-model with the property of step 1 with different values (e.g. 1 and 2);
  3. HTML - Show the value of the property of step 1;
  4. Check one checkbox.

Which browser?

Google Chrome version 62.0.3202.89 64 bits using VueMaterial 1.0.0-beta-4

What is expected?

Only the checked checkbox should be marked and the content of the property matrix binded to the checkbox should contain only the value of the checked checkbox. If another checkbox is checked, the array must also contain the checked value.

In summary, the array property must contain the value that represents the checked checkboxes.

What is actually happening?

  • Old version of VueMaterial: When any checkbox is checked all is checked (https://jsfiddle.net/JaderCM/2wt85dt5/)

  • Version 1.0.0-beta-4 of VueMaterial: The checkbox component is not rendered.

Reproduction Link

https://jsfiddle.net/JaderCM/2wt85dt5/7/

@marcosmoura
Copy link
Member

I will take a deep look. Have you tried this on a actual project or just on Codepen?

@JaderCM
Copy link
Author

JaderCM commented Nov 14, 2017

I would like to use in my current project. For now, I'm working in a alternative to this using md-button-toggle. So, for now I only have this example in a JSFiddle.

@Samuell1
Copy link
Member

Looks like jsfiddle have trouble to load Vue material

obrazok

@marcosmoura
Copy link
Member

The codepen examples are broken. I'm fixing this right now.

@JaderCM
Copy link
Author

JaderCM commented Nov 15, 2017

@Samuell1 even in browser, if we use the vue-material@beta with external references the same error occurs.

<script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>

@JaderCM
Copy link
Author

JaderCM commented Nov 15, 2017

@marcosmoura I found my error using the previous version of beta version. It's necessary use md-value instead value.

http://jsfiddle.net/JaderCM/2wt85dt5/14/

@marcosmoura
Copy link
Member

Can you check this now? Because the old version works with md-value, but the new one is value.

@JaderCM
Copy link
Author

JaderCM commented Nov 20, 2017

@marcosmoura could you tell me what's the url of the new version? The url https://unpkg.com/vue-material@beta throw an exception.

@Samuell1
Copy link
Member

Use codepen: https://codepen.io/Samuellsk/pen/gXKPYE?&editors=111#

@JaderCM
Copy link
Author

JaderCM commented Nov 23, 2017

Sorry @Samuell1 but this is not the solution. The reproduction link keep with the problem.

The example that I wrote represents my scenario. If I need do something in this reproductions steps to solve the problem, could you tell me exactly what I should do please?

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

@Samuell1 below is the same code that you wrote in codepen and not works for me. Could you tell me where I'm wrong please?

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
    <link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <style>
.md-checkbox {
  display: flex;
}
table {
  width: 100%;
  table-layout: fixed;

  th {
    text-align: left;
  }
}
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <md-checkbox v-model="boolean">Boolean</md-checkbox>
        <md-checkbox v-model="string" value="my-checkbox">String</md-checkbox>
        <md-checkbox v-model="novalue">No Value</md-checkbox>
        <md-checkbox v-model="disabled" disabled>Disabled</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
            <th>Boolean</th>
            <th>String</th>
            <th>No Value</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
            <td>{{ boolean }}</td>
            <td>{{ string }}</td>
            <td>{{ novalue }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script>
Vue.use(VueMaterial.default)

const example = 
{
  name: 'RegularCheckboxes',
  data: () => ({
    array: [],
    boolean: false,
    string: null,
    novalue: null,
    disabled: true
  })
}

new Vue({
  name: 'root',
  el: '#app',
  ...example
})
    </script>
  </body>
</html>

@Samuell1
Copy link
Member

Samuell1 commented Nov 24, 2017

Its not same, try adding https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js as script

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

Same problem:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  	<link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
  	<link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <style>
.md-checkbox {
  display: flex;
}
table {
  width: 100%;
  table-layout: fixed;

  th {
    text-align: left;
  }
}
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <md-checkbox v-model="boolean">Boolean</md-checkbox>
        <md-checkbox v-model="string" value="my-checkbox">String</md-checkbox>
        <md-checkbox v-model="novalue">No Value</md-checkbox>
        <md-checkbox v-model="disabled" disabled>Disabled</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
            <th>Boolean</th>
            <th>String</th>
            <th>No Value</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
            <td>{{ boolean }}</td>
            <td>{{ string }}</td>
            <td>{{ novalue }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script>
Vue.use(VueMaterial.default)

const example = 
{
  name: 'RegularCheckboxes',
  data: () => ({
    array: [],
    boolean: false,
    string: null,
    novalue: null,
    disabled: true
  })
}

new Vue({
  name: 'root',
  el: '#app',
  ...example
})
    </script>
  </body>
</html>

@Samuell1
Copy link
Member

Script needs to have type="text/babel"

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

Same problem:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
    <link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <script type="text/babel" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <style>
.md-checkbox {
  display: flex;
}
table {
  width: 100%;
  table-layout: fixed;

  th {
    text-align: left;
  }
}
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <md-checkbox v-model="boolean">Boolean</md-checkbox>
        <md-checkbox v-model="string" value="my-checkbox">String</md-checkbox>
        <md-checkbox v-model="novalue">No Value</md-checkbox>
        <md-checkbox v-model="disabled" disabled>Disabled</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
            <th>Boolean</th>
            <th>String</th>
            <th>No Value</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
            <td>{{ boolean }}</td>
            <td>{{ string }}</td>
            <td>{{ novalue }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script type="text/babel">
Vue.use(VueMaterial.default)

const example = 
{
  name: 'RegularCheckboxes',
  data: () => ({
    array: [],
    boolean: false,
    string: null,
    novalue: null,
    disabled: true
  })
}

new Vue({
  name: 'root',
  el: '#app',
  ...example
})
    </script>
  </body>
</html>

Could you past here the code that works for you please?

@Samuell1
Copy link
Member

that type needs to be only on javascript code not at source file

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

I tried both before post. Could you write here the code that works please?

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
    <link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <style>
.md-checkbox {
  display: flex;
}
table {
  width: 100%;
  table-layout: fixed;

  th {
    text-align: left;
  }
}
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <md-checkbox v-model="boolean">Boolean</md-checkbox>
        <md-checkbox v-model="string" value="my-checkbox">String</md-checkbox>
        <md-checkbox v-model="novalue">No Value</md-checkbox>
        <md-checkbox v-model="disabled" disabled>Disabled</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
            <th>Boolean</th>
            <th>String</th>
            <th>No Value</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
            <td>{{ boolean }}</td>
            <td>{{ string }}</td>
            <td>{{ novalue }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script type="text/babel">
Vue.use(VueMaterial.default)

const example = 
{
  name: 'RegularCheckboxes',
  data: () => ({
    array: [],
    boolean: false,
    string: null,
    novalue: null,
    disabled: true
  })
}

new Vue({
  name: 'root',
  el: '#app',
  ...example
})
    </script>
  </body>
</html>

@Samuell1
Copy link
Member

I using codepen. Do you get any errors in console?

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

I'm not using codepen because I need work with this framework in my workspace. Every time show the same error message:

Uncaught TypeError: Cannot read property 'addEventListener' of null
    at s (vue-material.min.js:1)
    at vue-material.min.js:1
    at Object.defineProperty.value (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at Object.defineProperty.value (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at Object.defineProperty.value (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at Object.defineProperty.value (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at Object.defineProperty.value (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at Object.g (vue-material.min.js:1)
    at t (vue-material.min.js:1)
    at e.exports.e (vue-material.min.js:1)
    at vue-material.min.js:1
    at n (vue-material.min.js:1)
    at vue-material.min.js:1

@Samuell1
Copy link
Member

Samuell1 commented Nov 24, 2017

I checked it and there is issues with babel

SyntaxError: embedded: Unexpected token (20:2)
browser.js:2028:13

Line 20:2 is ...example
Looks like browsers doesnt like destructuring objects

Working example:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  	<link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
  	<link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <style>
.md-checkbox {
  display: flex;
}
table {
  width: 100%;
  table-layout: fixed;

  th {
    text-align: left;
  }
}
    </style>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <md-checkbox v-model="boolean">Boolean</md-checkbox>
        <md-checkbox v-model="string" value="my-checkbox">String</md-checkbox>
        <md-checkbox v-model="novalue">No Value</md-checkbox>
        <md-checkbox v-model="disabled" disabled>Disabled</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
            <th>Boolean</th>
            <th>String</th>
            <th>No Value</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
            <td>{{ boolean }}</td>
            <td>{{ string }}</td>
            <td>{{ novalue }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <script type="text/babel">
Vue.use(VueMaterial.default);

new Vue({
  name: 'root',
  el: '#app',
  data: () => ({
    array: [],
    boolean: false,
    string: null,
    novalue: null,
    disabled: true
  })
});
    </script>
  </body>
</html>

@JaderCM
Copy link
Author

JaderCM commented Nov 24, 2017

@Samuell1 thank you for your help. In fact the problem is with vue-material. If I only move the reference of vue-material to the end works:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link type="text/css" rel="stylesheet" href="https://unpkg.com/vue-material@beta/dist/vue-material.min.css">
    <link type="text/css" rel="stylesheet" href="https://cdn.rawgit.com/vuematerial/vue-material/master/dist/default-theme.css">
    <script type="text/javascript" src="https://unpkg.com/vue"></script>
  </head>
  <body>
    <div id="app">
      <div>
        <md-checkbox v-model="array" value="1">Array</md-checkbox>
        <md-checkbox v-model="array" value="2">Array</md-checkbox>
        <table>
          <tr>
            <th>Array</th>
          </tr>
          <tr>
            <td>{{ array }}</td>
          </tr>
        </table>
      </div>
    </div>
    <script type="text/javascript" src="https://unpkg.com/vue-material@beta"></script>
    <script>
Vue.use(VueMaterial.default);

new Vue({
  name: 'root',
  el: '#app',
  data: () => ({
    array: []
  })
});
    </script>
  </body>
</html>

@Samuell1
Copy link
Member

@JaderCM problem was with destructing example object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants