Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1022 Widoki

Hi, now i will summary all the information: First Iam created a new selection (address) for survey.question --> I created a new template for this question.container too (my template worked). So , from this template , I need create js for user can select addresses according to each region.
i created my module , have some model for save my data geography , with that , Iam created  a model controller, Js file  --> This is my code controller:

@http.route('/survey/get_states', type='json', auth="public", website=True)
def get_states(self, country_id):
states = request.env['res.country.state'].sudo().search([('country_id', '=', int(country_id))])
return [{'id': state.id, 'name': state.name} for state in states]

@http.route('/survey/get_districts', type='json', auth="public", website=True)
def get_districts(self, state_id):
districts = request.env['res.country.district'].sudo().search([('state_id', '=', int(state_id))])
return [{'id': district.id, 'name': district.name} for district in districts]

@http.route('/survey/get_wards', type='json', auth="public", website=True)
def get_wards(self, district_id):
wards = request.env['res.country.ward'].sudo().search([('district_id', '=', int(district_id))])
return [{'id': ward.id, 'name': ward.name} for ward in wards]

And this my JS file , but when i press F12 , F5 -> I got error (
Uncaught Error: Dependencies should be defined by an array: function(require){"use strict";var publicWidget=require('web.public.widget');var core=require('web.core');var _t=core._t;var SurveyAddressWidget=publicWidget.Widget.extend({selector:'.js_address_widget',events:{'change .js_country':'_onCountryChange','change .js_state':'_onStateChange','change .js_district':'_onDistrictChange',},start:function(){return this._super.apply(this,arguments);},_onCountryChange:function(ev){var countryId=$(ev.currentTarget).val();this._updateStates(countryId);},_onStateChange:function(ev){var stateId=$(ev.currentTarget).val();this._updateDistricts(stateId);},_onDistrictChange:function(ev){var districtId=$(ev.currentTarget).val();this._updateWards(districtId);},_updateStates:function(countryId){var self=this;this._rpc({route:'/survey/get_states',params:{country_id:countryId,},}).then(function(states){var $stateSelect=self.$('.js_state');$stateSelect.empty().append($('


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
cze 24
1218
1
cze 24
1397
2
cze 24
1842
0
paź 24
1047
1
sie 24
2605