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]
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($('
0
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!