Skip to content

Commit

Permalink
Core: SmartSelect - get View dynamically to fallback on routable modals
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Jan 25, 2020
1 parent eac04ec commit 71445f4
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions src/core/components/smart-select/smart-select-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class SmartSelect extends Framework7Class {
}
}

// View
let view;

// Url
let url = params.url;
if (!url) {
Expand All @@ -68,7 +65,6 @@ class SmartSelect extends Framework7Class {
multiple,
inputType,
id,
view,
inputName: `${inputType}-${id}`,
selectName: $selectEl.attr('name'),
maxLength: $selectEl.attr('maxlength') || params.maxLength,
Expand Down Expand Up @@ -213,16 +209,18 @@ class SmartSelect extends Framework7Class {
return ss.$selectEl.val();
}

getView() {
const ss = this;
let view = ss.view || ss.params.view;
if (!view) {
view = ss.$el.parents('.view').length && ss.$el.parents('.view')[0].f7View;
get view() {
const { params, $el } = this;
let view;
if (params.view) {
view = params.view;
}
if (!view) {
view = $el.parents('.view').length && $el.parents('.view')[0].f7View;
}
if (!view && params.openIn === 'page') {
throw Error('Smart Select requires initialized View');
}
ss.view = view;
return view;
}

Expand Down Expand Up @@ -656,9 +654,8 @@ class SmartSelect extends Framework7Class {
if (ss.opened) return ss;
ss.getItemsData();
const pageHtml = ss.renderPage(ss.items);
const view = ss.getView();

view.router.navigate({
ss.view.router.navigate({
url: ss.url,
route: {
content: pageHtml,
Expand Down Expand Up @@ -708,9 +705,8 @@ class SmartSelect extends Framework7Class {
},
};

if (ss.params.routableModals) {
const view = ss.getView();
view.router.navigate({
if (ss.params.routableModals && ss.view) {
ss.view.router.navigate({
url: ss.url,
route: {
path: ss.url,
Expand Down Expand Up @@ -752,9 +748,8 @@ class SmartSelect extends Framework7Class {
},
};

if (ss.params.routableModals) {
const view = ss.getView();
view.router.navigate({
if (ss.params.routableModals && ss.view) {
ss.view.router.navigate({
url: ss.url,
route: {
path: ss.url,
Expand Down Expand Up @@ -790,9 +785,8 @@ class SmartSelect extends Framework7Class {
},
},
};
if (ss.params.routableModals) {
const view = ss.getView();
view.router.navigate({
if (ss.params.routableModals && ss.view) {
ss.view.router.navigate({
url: ss.url,
route: {
path: ss.url,
Expand Down Expand Up @@ -828,9 +822,8 @@ class SmartSelect extends Framework7Class {
close() {
const ss = this;
if (!ss.opened) return ss;
if (ss.params.routableModals || ss.openedIn === 'page') {
const view = ss.getView();
view.router.back();
if ((ss.params.routableModals && ss.view) || ss.openedIn === 'page') {
ss.view.router.back();
} else {
ss.modal.once('modalClosed', () => {
Utils.nextTick(() => {
Expand Down

0 comments on commit 71445f4

Please sign in to comment.