Conditional field: suggest candidates based on another field's value (Domain → Type) #18
Can a link field's suggestions depend on the value of another field in the same note? Example: a Is |
Replies: 3 comments 1 reply
|
Not a dumb question at all, and you already nailed the key part: When Fileclass builds the candidate list for a link field, it runs the bound Base view with the note you're editing as the view's context — so inside the view's filters/formulas For your Domain → Type case, assuming each formulas:
# true when this candidate's Domain equals the edited note's Domain
sameDomain: Domain.isTruthy() && this.Domain.isTruthy() && (Domain == this.Domain)
views:
- type: table
name: Types for this domain
filters:
and:
- formula.sameDomain == trueThen point the
The example compares Domain as a plain value (a word like Two gotchas worth knowing:
The I just documented this whole pattern here: https://mdelobelle.github.io/fileclass/fields/#conditional-candidates-dependent-fields ("Conditional candidates"). Give it a try and let me know how it goes! |
|
Follow-up: I've opened a feature request to make this a guided option in the field settings editor — pick the source field and Fileclass would forge the formula + view for you, no hand-written YAML — so the manual pattern above becomes the "under the hood" version rather than something you have to write yourself. Tracking it here: #19 👍 (thanks @Azmoinal — your question is what prompted it) |
|
Hi @mdelobelle, I've another doubt about the base that I'm using to return the list of values after the filtering. I've a case when the list is quite long so I would like to have list item in an ordered way to select them quickly. The same behaviour apply to Select and Multi. |
Not a dumb question at all, and you already nailed the key part:
thisworks. 🎉When Fileclass builds the candidate list for a link field, it runs the bound Base view with the note you're editing as the view's context — so inside the view's filters/formulas
thisresolves to that note, including its frontmatter properties viathis.<PropertyName>(not justthis.file). One base is enough; no need to spam one base per Domain value.For your Domain → Type case, assuming each
Typenote carries aDomainproperty, add a formula + a view to the base bound to theTypefield: