Using Ajax / custome JS to dynamically update states_list(), based on choice from countries_list() in same question?

huangapple go评论66阅读模式
英文:

Using Ajax / custome JS to dynamically update states_list(), based on choice from countries_list() in same question?

问题

我之前在面试中有两个问题,它们可以很好地配合使用。

实际上,第一个问题使用非常出色且非常有用的countries_list()函数来呈现国家列表。然后,第二个问题使用(同样)非常出色且非常有用的states_list()函数来呈现潜在州的下拉框,但修改为仅显示可能适用于用户的州,并根据需要修改标签“州”(如果国家中只有一个州,例如新加坡,则我还有一些代码跳过此问题)。


问题:|
你居住在哪个国家?
字段:

  • 国家: jurisdiction.country
    输入类型:下拉框
    代码:countries_list()

问题:|
你居住在哪个州?
字段:

  • ${ subdivision_type(jurisdiction.country) }: jurisdiction.state
    输入类型:下拉框
    代码:states_list(jurisdiction.country)

我想知道,是否有一种已知的方法可以通过input type: ajax就像这里)实现相同的“实时”效果,使用自定义JS或其他方法?

理想情况下,我可以使用subdivision_type()“实时重新加载”问题提示。

英文:

I have two questions earlier in my interview, that work great together.

Essentially, the first question presents a list of countries, using the very amazing and highly useful countries_list() function. The second question then presents a combobox of potential states using the (also) very amazing and highly useful states_list() function, but modified to only show the states that might apply to the user, and modifies the label "State" as appropriate (and I have some other code that skips this question if there is only one state in the country (eg. Singapore) ).

---
question: |
  What country do you live in?
fields:
 - Country: jurisdiction.country
   input type: combobox
   code: countries_list()
---
question: |
  What state do you live in?
fields:
 - ${ subdivision_type(jurisdiction.country) }: jurisdiction.state
   input type: combobox
   code: states_list(jurisdiction.country)
---

What I'm wondering, is if there's a known way to accomplish this same effect "live" on a page using input type: ajax (as here), custom JS, or some other method?

Ideally, I could "live reload" the question prompt with subdivision_type() as well.

答案1

得分: 1

在docassemble文档中有一个类似的示例,链接如下:

https://docassemble.org/docs/background.html#background_response_choices

然而,这个示例没有使用JavaScript来更新"State"字段的标签。不过,您可以编写自己的JavaScript来实现这一点。

另一种可能性是使用本节中描述的策略,在用户更改国家时刷新屏幕:

https://docassemble.org/docs/background.html#background_response_refresh

英文:

There is a similar example in the docassemble documentation here:

https://docassemble.org/docs/background.html#background_response_choices

This does not update the label of the State field using JavaScript, however. You could write your own JavaScript to accomplish that somehow.

Another possibility would be to use the strategy described in this section to refresh the screen when a user changes the country:

https://docassemble.org/docs/background.html#background_response_refresh

huangapple
  • 本文由 发表于 2023年6月8日 10:38:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428245.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定