def field_changed(request): """ Ajax callback called when a trigger field or base field has changed. Returns html for new options and details for the dependent field as json. """ hashed_name = request.POST.__getitem__('hashed_name') widget = FlexSelectWidget.instances[hashed_name] instance = instance_from_request(request, widget) try: value_fk = getattr(instance, widget.base_field.name) except: value_fk = None if bool(int(request.POST.__getitem__('include_options'))): choices = choices_from_instance(instance, widget) options = Select(choices=choices).render_options( [], [value_fk.pk if value_fk else None]) else: options = None return HttpResponse(json.dumps({ 'options': options, 'details': details_from_instance(instance, widget), }), content_type='application/json')
def field_changed(request): """ Ajax callback called when a trigger field or base field has changed. Returns html for new options and details for the dependent field as json. """ hashed_name = request.POST.__getitem__('hashed_name') widget = FlexSelectWidget.instances[hashed_name] instance = instance_from_request(request, widget) if bool(int(request.POST.__getitem__('include_options'))): choices = choices_from_instance(instance, widget) options = Select(choices=choices).render_options([], []) else: options = None return HttpResponse(json.dumps({ 'options': options, 'details': details_from_instance(instance, widget), }), mimetype='application/json')
def field_changed(request): """ Ajax callback called when a trigger field or base field has changed. Returns html for new options and details for the dependent field as json. """ hashed_name = request.POST.__getitem__('hashed_name') widget = FlexSelectWidget.instances[hashed_name] instance = instance_from_request(request, widget) if bool(int(request.POST.__getitem__('include_options'))): choices = choices_from_instance(instance, widget) options = CustomSelectWidget(choices=choices).render_options([], []) else: options = None return HttpResponse( json.dumps({ 'options': options, 'details': details_from_instance(instance, widget), }))
def field_changed(request): """ Ajax callback called when a trigger field or base field has changed. Returns html for new options and details for the dependent field as json. """ hashed_name = request.POST.__getitem__('hashed_name') # if hashed_name in FlexSelectWidget.__class__.instances: widget = Storage().__class__.instances[hashed_name] instance = instance_from_request(request, widget) try: value_fk = getattr(instance, widget.base_field.name) except Exception: value_fk = None if bool(int(request.POST.__getitem__('include_options'))): choices = choices_from_instance(instance, widget) options = Select(choices=choices).render_options([], [value_fk.pk if value_fk else None]) else: options = None return HttpResponse(json.dumps({ 'options' : options, 'details': details_from_instance(instance, widget), }), mimetype='application/json')