From b9285e320a71a2c531e86d90b8ef3813d34606c4 Mon Sep 17 00:00:00 2001 From: Victor Marin <36818606+mdvictor@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:46:25 +0300 Subject: [PATCH] Fix new dashboard save name validation (#86290) --- .../dashboard-scene/saving/SaveDashboardAsForm.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx b/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx index 29263390f67..edc3677e1b1 100644 --- a/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx +++ b/public/app/features/dashboard-scene/saving/SaveDashboardAsForm.tsx @@ -1,5 +1,5 @@ import debounce from 'debounce-promise'; -import React from 'react'; +import React, { ChangeEvent } from 'react'; import { UseFormSetValue, useForm } from 'react-hook-form'; import { Dashboard } from '@grafana/schema'; @@ -28,7 +28,7 @@ export interface Props { export function SaveDashboardAsForm({ dashboard, changeInfo }: Props) { const { changedSaveModel } = changeInfo; - const { register, handleSubmit, setValue, formState, getValues, watch, trigger } = useForm({ + const { register, handleSubmit, setValue, formState, getValues, watch } = useForm({ mode: 'onBlur', defaultValues: { title: changeInfo.isNew ? changedSaveModel.title! : `${changedSaveModel.title} Copy`, @@ -97,10 +97,9 @@ export function SaveDashboardAsForm({ dashboard, changeInfo }: Props) { { - trigger('title'); + onChange={debounce(async (e: ChangeEvent) => { + setValue('title', e.target.value, { shouldValidate: true }); }, 400)} - autoFocus />