Skip to content
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

Dynamic URL route matching with Params #10

Open
cafadev opened this issue May 4, 2024 · 0 comments · May be fixed by #14
Open

Dynamic URL route matching with Params #10

cafadev opened this issue May 4, 2024 · 0 comments · May be fixed by #14
Assignees
Labels
beta feature New feature or request in progress

Comments

@cafadev
Copy link
Contributor

cafadev commented May 4, 2024

Describe

Currently, we have the lookupField and lookupValue to dynamically insert values in the settings.url for both forms or tables. But this is very limited when we need to add more than one dynamic value in the URL.

Propose

Allow dynamic URL route matching with parameters. This idea is absolutely inspired by vue-router.

To achieve this behavior, we can use the dynamic placeholders that we're currently using on the button's labels

<script lang="ts" setup>
const form = useForm({
  // Other properties...

  settings: {
    url: '{{ albums/:album_id/tracks | albums/:album_id/tracks/:id }}',
  },
})
</script>

Another way to achieve this behavior is accepting a function on the URL. The function should receive the formMode and the record object, then should return the URL string.

<script lang="ts" setup>
const form = useForm({
  // Other properties...

  settings: {
    url: (context: { mode: FormMode; record: any }): string => {
      const { mode, record } = context
      const CREATE_URL = `albums/${record.albumId}/tracks`
      const UPDATE_URL = `albums/${record.albumId}/tracks/${record.id}`

      return mode === FORM_MODE.create ? CREATE_URL : UPDATE_URL
    },
  },
})
</script>
@cafadev cafadev added the feature New feature or request label May 4, 2024
@cafadev cafadev self-assigned this May 19, 2024
@cafadev cafadev linked a pull request Jul 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta feature New feature or request in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant