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

Add url setting type #2327

Merged
merged 2 commits into from
Jan 23, 2025
Merged

Add url setting type #2327

merged 2 commits into from
Jan 23, 2025

Conversation

huchenlei
Copy link
Member

@huchenlei huchenlei commented Jan 23, 2025

Add URL Input Component

Changes

  • Added new UrlInput component with validation
  • Supports real-time URL format checking and reachability testing
  • Visual feedback for loading, valid, and invalid states
  • Integrated with existing form system

image

  {
    id: 'Comfy.Server.ServerUrl',
    name: 'Server URL',
    type: 'url',
    defaultValue: 'http://localhost:8188'
  }

┆Issue is synchronized with this Notion page by Unito

@huchenlei huchenlei requested a review from a team as a code owner January 23, 2025 16:19
@huchenlei huchenlei merged commit 0ab1d97 into main Jan 23, 2025
9 of 10 checks passed
@huchenlei huchenlei deleted the url_form_field branch January 23, 2025 16:25
@christian-byrne
Copy link
Collaborator

What's the reason for not using primevue form field component?

@huchenlei
Copy link
Member Author

What's the reason for not using primevue form field component?

The component is designed to be used in settings dialog, which is currently not a primevue form.

@christian-byrne
Copy link
Collaborator

The component itself can be a form, which allows for validation with zod, validation/interaction state managament, conditional error components, and so on.

@christian-byrne
Copy link
Collaborator

<template>
  <Form>
    <FormField
      v-slot="$field"
      name="url"
      :resolver="zodResolver(urlSchema)"
      :validate-on-blur="true"
      :validate-on-mount="true"
    >
      <IconField>
        <InputText v-bind="$field" class="w-full" :model-value="modelValue" />
        <InputIcon
          v-if="$field.value && !$field.valid"
          class="pi pi-times text-red-500"
        />
        <InputIcon
          v-else-if="$field.touched && $field.valid"
          class="pi pi-check text-green-500"
        />
        <InputIcon
          v-else-if="$field.dirty && $field.value"
          class="pi pi-spin pi-spinner text-neutral-400"
        />
      </IconField>
    </FormField>
  </Form>
</template>

<script setup lang="ts">
import { Form, FormField } from '@primevue/forms'
import { zodResolver } from '@primevue/forms/resolvers/zod'
import IconField from 'primevue/iconfield'
import InputIcon from 'primevue/inputicon'
import InputText from 'primevue/inputtext'
import { z } from 'zod'

import { checkUrlReachable } from '@/utils/networkUtil'

const { modelValue, validateUrlFn } = defineProps<{
  modelValue: string
  validateUrlFn?: (url: string) => Promise<boolean>
}>()

const urlSchema = z
  .string()
  .url()
  .refine(checkUrlReachable)
  .refine(validateUrlFn ?? (() => true))
  .optional()

// Add inheritAttrs option to prevent attrs from being applied to root element
defineOptions({
  inheritAttrs: false
})
</script>

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