Skip to content

Commit

Permalink
tidy some binding validation messages (sveltejs#2300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed Mar 23, 2019
1 parent d6b9991 commit c06af2d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,12 @@ export default class Element extends Node {
});
}

if (check_type_attribute() !== 'checkbox') {
component.error(binding, {
code: `invalid-binding`,
message: `'${name}' binding can only be used with <input type="checkbox">`
});
const type = check_type_attribute();

if (type !== 'checkbox') {
let message = `'${name}' binding can only be used with <input type="checkbox">`;
if (type === 'radio') message += ` — for <input type="radio">, use 'group' binding`;
component.error(binding, { code: `invalid-binding`, message });
}
} else if (name === 'group') {
if (this.name !== 'input') {
Expand All @@ -512,14 +513,14 @@ export default class Element extends Node {
if (type !== 'checkbox' && type !== 'radio') {
component.error(binding, {
code: `invalid-binding`,
message: `'checked' binding can only be used with <input type="checkbox"> or <input type="radio">`
message: `'group' binding can only be used with <input type="checkbox"> or <input type="radio">`
});
}
} else if (name == 'files') {
if (this.name !== 'input') {
component.error(binding, {
code: `invalid-binding`,
message: `'files' binding acn only be used with <input type="file">`
message: `'files' is not a valid binding on <${this.name}> elements`
});
}

Expand Down

0 comments on commit c06af2d

Please sign in to comment.