Skip to content

Commit 7093a60

Browse files
committed
fixed Vue.js browser console error with inital templates containing forms
1 parent dbcd409 commit 7093a60

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%component{dynamic_tag_attributes.merge('initial-template': "#{render_content}")}
1+
%component{dynamic_tag_attributes.merge('v-bind:initial-template': "#{render_content.to_json}")}
22
%div{class: "matestack-cable-component-container", "v-bind:class": "{ 'loading': loading === true }"}
33
%div{class: "matestack-cable-component-wrapper", "v-if": "cableTemplate != null", "v-bind:class": "{ 'loading': loading === true }"}
44
%v-runtime-template{":template":"cableTemplate"}

spec/test/components/dynamic/cable/cable_spec.rb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
include Utils
55
include Matestack::Ui::Core::ApplicationHelper
66

7+
before :each do
8+
9+
end
10+
711
it 'should have the typical matestack wrapping classes' do
812
matestack_render do
913
cable id: 'foobar' do
@@ -42,7 +46,7 @@
4246
expect(page).to have_selector('h1#id', text: 'replaced')
4347
reset_matestack_app
4448
end
45-
49+
4650
it 'should be possible to add vue.js components' do
4751
matestack_render do
4852
cable id: 'cable-replace', replace_on: 'replace' do
@@ -67,4 +71,46 @@
6771
expect(page).to have_content('event successful emitted')
6872
end
6973

74+
it 'should render Vue.js components and forms without Vue.js console error' do
75+
# unfortunately I can't test this as I'm not getting the browsers console.log via capybara/Selenium
76+
# tried all hints found on Stackoverflow etc
77+
matestack_render do
78+
cable id: 'cable-replace', replace_on: 'replace' do
79+
form for: :some_object, path: "/", method: :post do
80+
form_input key: :foo, type: :text, label: :foo, id: :foo
81+
end
82+
end
83+
end
84+
85+
# this was throwing a console error in v.1.3.0
86+
# "Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">."
87+
# fixed in v.1.3.1 without explicitly testing it...
88+
89+
expect(page).to have_selector('form')
90+
expect(page).to have_selector('input#foo')
91+
end
92+
93+
it 'should work without any initial body given' do
94+
matestack_render do
95+
cable id: 'cable-replace', replace_on: 'replace' do
96+
# nothing
97+
end
98+
toggle show_on: 'test' do
99+
plain 'event successful emitted'
100+
end
101+
end
102+
103+
expect(page).not_to have_content('event successful emitted')
104+
105+
onclick = matestack_component(:onclick, emit: :test) { button text: 'Click' }
106+
script = "MatestackUiCore.matestackEventHub.$emit('replace', { data: \"#{onclick}\" })".gsub("\n", "")
107+
page.execute_script(script)
108+
109+
expect(page).to have_selector('button', text: 'Click')
110+
expect(page).not_to have_content('event successful emitted')
111+
112+
click_on 'Click'
113+
expect(page).to have_content('event successful emitted')
114+
end
115+
70116
end

0 commit comments

Comments
 (0)