Skip to content

Commit a5f3463

Browse files
committed
changed scope_ref to matestack_ui_vuejs_ref, matestack-ui-core-ref to matestack-ui-vuejs-ref, fixed form components ID rendering and added related specs, fixed hierarchy of getElement method, removed not used utils module
1 parent b76ea29 commit a5f3463

File tree

17 files changed

+220
-95
lines changed

17 files changed

+220
-95
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v3.0.0.rc2 Release - 2022-02-15
4+
5+
### Bugfixes
6+
7+
- fixed ID rendering on form input components
8+
39
## v3.0.0.rc1 Release - 2022-02-11
410

511
- please read the [migration guide](docs/migrate-to-3.0.md)

lib/matestack/ui/vue_js.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module VueJs
1111

1212
require "#{vue_js_base_path}/version"
1313

14-
require "#{vue_js_base_path}/utils"
1514
require "#{vue_js_base_path}/vue_attributes"
1615
require "#{vue_js_base_path}/vue"
1716
require "#{vue_js_base_path}/components/app"

lib/matestack/ui/vue_js/components/form/base.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def form_context
1212
end
1313

1414
def component_attributes
15-
super.merge("matestack-ui-core-ref": "#{form_context.component_uid}-#{component_id}")
15+
super.merge("matestack-ui-vuejs-ref": "#{form_context.component_uid}-#{component_id}")
1616
end
1717

1818
def component_id
@@ -45,7 +45,11 @@ def id
4545
if ctx.id.present?
4646
"'#{ctx.id}'"
4747
else
48-
"'#{key}'+vc.parentNestedFormRuntimeId"
48+
if form_context.is_nested_form?
49+
"'#{key}'+vc.parentNestedFormRuntimeId"
50+
else
51+
"'#{key}'"
52+
end
4953
end
5054
end
5155

@@ -61,7 +65,7 @@ def placeholder
6165

6266
def attributes
6367
(options || {}).merge({
64-
"matestack-ui-core-ref": scoped_ref("input.#{attribute_key}"),
68+
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("input.#{attribute_key}"),
6569
":id": id,
6670
type: ctx.type,
6771
multiple: ctx.multiple,

lib/matestack/ui/vue_js/components/form/checkbox.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def checkbox_attributes(item)
4747
type: :checkbox,
4848
name: item_label(item),
4949
"#{value_key(item)}": item_value(item),
50-
"matestack-ui-core-ref": scoped_ref("select.multiple.#{key}"),
50+
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("select.multiple.#{key}"),
5151
'v-on:change': change_event,
5252
'init-value': (init_value || []).to_json,
5353
'v-bind:class': "{ '#{error_class}': #{error_key} }",

lib/matestack/ui/vue_js/components/form/fields_for_add_item.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const componentDef = {
1414
],
1515
methods: {
1616
addItem: function(key){
17-
var templateString = JSON.parse(this.getElement().querySelector('#prototype-template-for-'+key).dataset[":template"])
17+
var templateString = JSON.parse(this.getTemplateElement().querySelector('#prototype-template-for-'+key).dataset[":template"])
1818
var tmp_dom_elem = document.createElement('div')
1919
tmp_dom_elem.innerHTML = templateString
2020
var static_prototype_template_uid = tmp_dom_elem.querySelector('matestack-component-template').id.replace("uid-", "")

lib/matestack/ui/vue_js/components/form/form.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def response
2525
def attributes
2626
{
2727
class: 'matestack-form',
28-
"matestack-ui-core-ref": scoped_ref('form'),
28+
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref('form'),
2929
'v-bind:class': "{ 'has-errors': vc.hasErrors(), loading: vc.loading }",
3030
'v-on:submit.prevent': 'vc.perform',
3131
}

lib/matestack/ui/vue_js/components/form/nested_form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ const componentDef = {
106106
this.parentDeletedNestedForms[this.props["fields_for"]] = [];
107107
}
108108

109-
var id = parseInt(self.getElement().querySelector('.matestack-form-fields-for').id.replace(this.props["fields_for"]+"_child_", ""))
109+
var id = parseInt(self.getTemplateElement().querySelector('.matestack-form-fields-for').id.replace(this.props["fields_for"]+"_child_", ""))
110110

111111
//setup data binding for serverside rendered nested forms
112112
if (isNaN(id)){
113113
id = this.parentNestedForms[this.props["fields_for"]].length
114114
this.nestedFormRuntimeId = "_"+this.props["fields_for"]+"_child_"+id
115-
this.getElement().id = this.props["fields_for"]+"_child_"+id
115+
this.getTemplateElement().id = this.props["fields_for"]+"_child_"+id
116116
this.initValues()
117117
this.parentFormData[this.props["fields_for"]].push(this.data);
118118
this.parentNestedForms[this.props["fields_for"]].push(this);

lib/matestack/ui/vue_js/components/form/radio.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def radio_attributes(item)
3636
":id": item_id(item),
3737
name: item_name(item),
3838
type: :radio,
39-
"matestack-ui-core-ref": scoped_ref("select.#{key}"),
39+
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("select.#{key}"),
4040
'value-type': value_type(item_value(radio_options.first))
4141
}).tap do |attrs|
4242
attrs[value_key(item)] = item_value(item)

lib/matestack/ui/vue_js/components/form/select.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def select_attributes
4444
attributes.except(:options).merge({
4545
multiple: multiple,
4646
":id": id,
47-
"matestack-ui-core-ref": scoped_ref("select#{'.multiple' if multiple}.#{key}"),
47+
"matestack-ui-vuejs-ref": matestack_ui_vuejs_ref("select#{'.multiple' if multiple}.#{key}"),
4848
'value-type': value_type(select_options.first),
4949
'init-value': init_value,
5050
})

lib/matestack/ui/vue_js/components/mixin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matestackEventHub from '../event_hub'
22

33
const componentMixin = {
4-
props: ['props', 'params', 'matestack-ui-core-ref'],
4+
props: ['props', 'params', 'matestack-ui-vuejs-ref'],
55
computed: {
66
vc: function(){
77
return this;
@@ -15,13 +15,13 @@ const componentMixin = {
1515
// that's the reason for the following workaround
1616
var componentScopedRefs = {};
1717
var scopeId = this.props['component_uid'];
18-
var componentRelativeRefs = this.getElement().querySelectorAll("[matestack-ui-core-ref]")
18+
var componentRelativeRefs = this.getTemplateElement().querySelectorAll("[matestack-ui-vuejs-ref]")
1919
// var defaultSlot = this.$slots.default({ vc: this.vc })[0]
2020
// var globalRefs = defaultSlot.context.$refs
2121
for (let i in componentRelativeRefs) {
2222
let node = componentRelativeRefs[i]
2323
if (node.getAttribute){
24-
let nodeRef = node.getAttribute("matestack-ui-core-ref")
24+
let nodeRef = node.getAttribute("matestack-ui-vuejs-ref")
2525
if(nodeRef.startsWith(scopeId)){
2626
componentScopedRefs[nodeRef.replace(scopeId+"-", "")] = node
2727
}
@@ -30,9 +30,12 @@ const componentMixin = {
3030
}
3131
return componentScopedRefs;
3232
},
33-
getElement: function(){
33+
getTemplateElement: function(){
3434
return document.getElementById("uid-"+this.props['component_uid']);
3535
},
36+
getElement: function(){
37+
return this.getTemplateElement().firstChild;
38+
},
3639
registerEvents: function(events, callback){
3740
if(events != undefined){
3841
var event_names = events.split(",")

0 commit comments

Comments
 (0)