Skip to content

Commit

Permalink
fix: prop functions this context not resolved in build
Browse files Browse the repository at this point in the history
  • Loading branch information
ayZagen committed May 6, 2020
1 parent 582478d commit 320379c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/ui/directives/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ function translate(el: any, binding: DirectiveBinding,
return
}

// @ts-ignore
const $i18n = binding?.instance?.$i18n
const $i18n = binding?.instance?.$.appContext.config.globalProperties.$i18n
el._vt = el.textContent = $i18n?.t(path, ...makeParams(locale, args))
el._locale = $i18n?.locale
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui/views/FillMissing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:type="options.type"
:label="options.label"
:rules="options.validator ?
[ validate.bind( $i18n, options) ] : undefined"
[ validate.bind( null, options) ] : undefined"
/>
</template>

Expand All @@ -41,7 +41,8 @@

<script lang="ts">
import PlusAuth from 'plusauth-js';
import { defineComponent, inject, reactive, ref } from 'vue';
import { defineComponent, getCurrentInstance,
inject, reactive, ref } from 'vue';
import { PForm } from '../components';
import { AdditionalFields } from '../interfaces';
Expand Down Expand Up @@ -90,6 +91,7 @@ export default defineComponent({
}
},
setup(props){
const vm = getCurrentInstance()
const api = inject('api') as PlusAuth
const loading = ref(false)
const form = ref<InstanceType<typeof PForm>>(null as any)
Expand Down Expand Up @@ -132,7 +134,11 @@ export default defineComponent({
},
validate: function (options: any, value: any): any {
if(options.validator){
return options.validator.call(this,props.fields, value)
return options.validator.call(
vm?.appContext.config.globalProperties.$i18n,
props.fields,
value
)
}else {
return undefined
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui/views/ForgotPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:error-messages="options.errors"
:label="options.label"
:rules="options.validator ?
[ validate.bind( $i18n, options) ] : undefined"
[ validate.bind( null, options) ] : undefined"
/>
</template>

Expand Down Expand Up @@ -65,7 +65,8 @@

<script lang="ts">
import PlusAuth from 'plusauth-js';
import { defineComponent, inject, reactive, ref } from 'vue';
import { defineComponent, getCurrentInstance,
inject, reactive, ref } from 'vue';
import { PForm } from '../components';
import { AdditionalFields } from '../interfaces';
Expand Down Expand Up @@ -99,6 +100,7 @@ export default defineComponent({
},
},
setup(props){
const vm = getCurrentInstance()
const api = inject('api') as PlusAuth
const form = ref<InstanceType<typeof PForm>>(null as any)
const loading = ref(false)
Expand All @@ -112,7 +114,11 @@ export default defineComponent({
resolveClientLogo,
validate: function (options: any, value: any): any {
if(options.validator){
return options.validator.call(this,props.fields, value)
return options.validator.call(
vm?.appContext.config.globalProperties.$i18n,
props.fields,
value
)
}else {
return undefined
}
Expand Down
16 changes: 11 additions & 5 deletions src/ui/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:label="options.label"
:error-messages="options.errors"
:rules="options.validator ?
[ validate.bind( $i18n, options) ] : undefined"
[ validate.bind(null, options ) ] : undefined"
/>
</template>

Expand Down Expand Up @@ -81,7 +81,8 @@

<script lang="ts">
import PlusAuth from 'plusauth-js';
import { defineComponent, reactive, ref, inject } from 'vue';
import { defineComponent, reactive,
ref, inject, getCurrentInstance } from 'vue';
import { PForm } from '../components';
import SocialConnectionButton from '../components/SocialConnectionButton';
Expand Down Expand Up @@ -111,7 +112,7 @@ export default defineComponent({
type: 'text',
label: 'login.username',
errors: [],
validator(fields, value){
validator: function (fields, value){
if(!value){
return this.t('login.errors.usernameRequired')
}
Expand All @@ -122,7 +123,7 @@ export default defineComponent({
type: 'password',
label: 'login.password',
errors: [],
validator(fields, value){
validator: function (fields, value){
if(!value){
return this.t('login.errors.passwordRequired')
}
Expand All @@ -133,6 +134,7 @@ export default defineComponent({
},
},
setup(props){
const vm = getCurrentInstance()
const api = inject('api') as PlusAuth
const form = ref<InstanceType<typeof PForm>>(null as any)
const passwordVisible = ref(false)
Expand All @@ -145,7 +147,11 @@ export default defineComponent({
passwordVisible,
validate: function (options: any, value: any) {
if(options.validator){
return options.validator.call(this, props.fields, value)
return options.validator.call(
vm?.appContext.config.globalProperties.$i18n,
props.fields,
value
)
}else {
return undefined
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui/views/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:type="options.type"
:label="options.label"
:rules="options.validator ?
[ validate.bind( $i18n, options) ] : undefined"
[ validate.bind( null, options) ] : undefined"
/>
</template>
<div class="pt-4">
Expand Down Expand Up @@ -81,7 +81,8 @@

<script lang="ts" >
import PlusAuth from 'plusauth-js';
import { defineComponent, inject, reactive, ref } from 'vue';
import { defineComponent, getCurrentInstance,
inject, reactive, ref } from 'vue';
import { PForm } from '../components';
import SocialConnectionButton from '../components/SocialConnectionButton';
Expand Down Expand Up @@ -153,6 +154,7 @@ export default defineComponent({
}
},
setup(props){
const vm = getCurrentInstance()
const api = inject('api') as PlusAuth
const form = ref<InstanceType<typeof PForm>>(null as any)
const loading = ref(false)
Expand All @@ -163,7 +165,11 @@ export default defineComponent({
resolveClientLogo,
validate: function (options: any, value: any) {
if(options.validator){
return options.validator.call(this,props.fields, value)
return options.validator.call(
vm?.appContext.config.globalProperties.$i18n,
props.fields,
value
)
}else {
return undefined
}
Expand Down
12 changes: 9 additions & 3 deletions src/ui/views/ResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
:error-messages="options.errors"
:label="options.label"
:rules="options.validator ?
[ validate.bind( $i18n, options) ] : undefined"
[ validate.bind( null, options) ] : undefined"
/>
</template>

Expand All @@ -65,7 +65,8 @@

<script lang="ts">
import PlusAuth from 'plusauth-js';
import { defineComponent, inject, reactive, ref } from 'vue';
import { defineComponent, getCurrentInstance,
inject, reactive, ref } from 'vue';
import { useRoute } from 'vue-router';
Expand Down Expand Up @@ -116,6 +117,7 @@ export default defineComponent({
},
},
setup(props){
const vm = getCurrentInstance()
const api = inject('api') as PlusAuth
const form = ref<InstanceType<typeof PForm>>(null as any)
const codeForm = ref<InstanceType<typeof PForm>>(null as any)
Expand All @@ -133,7 +135,11 @@ export default defineComponent({
resolveClientLogo,
validate: function (options: any, value: any): any {
if(options.validator){
return options.validator.call(this,props.fields, value)
return options.validator.call(
vm?.appContext.config.globalProperties.$i18n,
props.fields,
value
)
}else {
return undefined
}
Expand Down

0 comments on commit 320379c

Please sign in to comment.