8000 ui.{createView,itemView}.isRequired function on fields by emmatown · Pull Request #9626 · keystonejs/keystone · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ui.{createView,itemView}.isRequired function on fields #9626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025

Conversation

emmatown
Copy link
Member
@emmatown emmatown commented Jun 12, 2025

This adds ui.{createView,itemView}.isRequired functions with similar behaviour to #9620 to allow client-side conditionals.

For example, it could be used like this:

priority: select({
  type: 'enum',
  options: [
    { label: 'Low', value: 'low' },
    { label: 'Medium', value: 'medium' },
    { label: 'High', value: 'high' },
  ],
}),
reasonForHighPriority: text({
  ui: {
    createView: {
      fieldMode: {
        edit: {
          priority: { equals: 'high' },
        },
      },
      isRequired: {
        priority: { equals: 'high' },
      },
    },
    itemView: {
      fieldMode: {
        edit: {
          priority: { equals: 'high' },
        },
      },
      isRequired: {
        priority: { equals: 'high' },
      },
    },
  },
  hooks: {
    validate: async ({ resolvedData, addValidationError, operation, item }) => {
      if (operation === 'delete') return
      const priority = resolvedData.priority ?? item?.priority
      const reason = resolvedData.reasonForHighPriority ?? item?.reasonForHighPriority
      if (priority === 'high' && !reason) {
        addValidationError('Reason for high priority is required when priority is high')
      }
    },
  },
}),

@emmatown emmatown marked this pull request as draft June 12, 2025 04:42
@emmatown emmatown force-pushed the push-tzmurtpoymxu branch 8 times, most recently from f1c1a2d to 2b3c0cb Compare June 12, 2025 05:17
@emmatown emmatown marked this pull request as ready for review June 12, 2025 05:21
@emmatown emmatown force-pushed the push-tzmurtpoymxu branch from 2b3c0cb to 6996ba5 Compare June 17, 2025 01:53
@dcousens dcousens merged commit 172f97b into main Jun 18, 2025
50 checks passed
@dcousens dcousens deleted the push-tzmurtpoymxu branch June 18, 2025 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0