react-hook-form 相关问题


useForm 和react-hook-form 在我与NextJs 一起使用时出现问题

我正在 NextJs 中编码,我需要使用“useForm”,但它不断给出错误......“无法解析“react-hook-form”。”请帮忙。 从“反应”导入反应; 导入{使用...


使用 Yup

我正在创建一个身份验证表单,并且正在引用有关如何使用 yup 验证我的输入的react-hook-form 文档。据我所知,一切都与实施提供的几乎相同...


如何在react-hook-form中将数值注册为嵌套属性?

我有一个名为 Totals 的属性,它应该包含多个嵌套对象作为属性。 这是我想要的表单结构: { 总计:{ 0:{ 值:0, }, }, }; 然而...


react-hook-form useForm 每次在 Nextjs 页面路由上执行

嗨,我是 Nextjs(v14) 的新手。我想使用react-hook-form 实现多页面表单。 然而,似乎每次都会执行useForm,并且defaultValues是在页面路由中设置的(点击 嗨,我是 Nextjs(v14) 的新手。我想使用react-hook-form 实现多页面表单。 不过,好像每次都会执行useForm,并且在页面路由时设置defaultValues(点击<Link to=XX>)。 如何跨多个页面保存表单数据? 请帮助我。 这是我的代码。 _app.tsx return ( <div> <FormProvider> <Component {...pageProps} /> </FormProvider> </div> ); FormProvider.tsx export const FormProvider = ({ children, }: { children: React.ReactNode; }) => { const defaultValues: MyForm = { name: '', description: '' }; const form = useForm({ defaultValues, resolver: zodResolver(MyFormSchema), }); const onSubmit = () => console.log("something to do"); return ( <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)}>{children}</form> </Form> ); }; 您正在寻找的是跨多个页面维护的某种全局状态。对于这个例子,我将使用 React 的上下文 API,如果这不适合您的用例,您可以找到一些其他状态管理库。 首先,您需要创建一个全局上下文,并在表单提供程序中包含一个全局状态 // FormProvider.tsx import { createContext, useContext, useState } from 'react'; const FormContext = createContext(); // Exported to be used in other components export const useFormContext = () => useContext(FormContext); export const FormProvider = ({ children }) => { const [formData, setFormData] = useState({}); return ( <FormContext.Provider value={{ formData, setFormData }}> {children} </FormContext.Provider> ); }; 现在您需要用 FormProvider 包装您的应用程序 // You are already doing this part //_app.tsx return ( <div> <FormProvider> <Component {...pageProps} /> </FormProvider> </div> ) 现在你可以像这样使用它了。请记住,您将更新表单的全局状态,该状态将在您的所有页面上发生变化。 // In your form component import { useForm } from 'react-hook-form'; import { useFormContext } from '../path/to/formContext'; const MyFormComponent = () => { const { formData, setFormData } = useFormContext(); const { register, handleSubmit } = useForm({ defaultValues: formData, resolver: zodResolver(MyFormSchema), }); const onSubmit = (data) => { setFormData(data); // Handle form submission }; return ( <form onSubmit={handleSubmit(onSubmit)}> {/* Form fields */} </form> ); }; 您可以从其他页面访问数据的示例 // In another page or component import { useFormContext } from '../path/to/formContext'; const AnotherPage = () => { const { formData } = useFormContext(); // Use formData as needed };


如何在react-hook-form中将数字值注册为嵌套属性

我有一个名为 Totals 的属性,它应该包含多个嵌套对象作为属性。 这是我想要的表单结构: { 总计:{ 0:{ 值:0, }, }, }; 然而...


PlateJS 序列化 HTML

我正在尝试这样做,以便当我单击按钮时,我可以获得一个 html 字符串。 一般来说,这个富文本编辑器会在React-Hook-Form内部,当提交表单时,它会保存


无法在react useEffect hook 中更新状态

即使使用了异步,我也无法更新useEffect中的数据。 注意:我不想在 useEffect 中添加数据作为依赖项,因为我只想获取一次数据 从“react&...


如何使用 yup 不允许在 React hook 中使用特殊字符和空格

代码如下: { 标签:“名称”, 名称:“名称”, 占位符:'名称', 类型:“文本”, 规则: yup.string() .required('姓名为必填项...


TypeScript 自定义 useStateIfMounted React Hook - 并非类型 'T | 的所有组成部分((value: SetStateAction<T>) => void)' 可调用

完整错误: 并非所有成分都是 'T | 类型((value: SetStateAction) => void)' 是可调用的。 “T”类型没有呼叫签名。 概括: 我正在尝试创建一个 useStateIfMounted c...


如何在 Redux Saga 中使用 React Hook?

我正在为我的应用程序设置语言。但我有一个问题。 我使用 React.useContext() 来设置语言。但是当我在 saga 的 toast 中修复它时,它会记录: [错误:无效的挂钩调用。 Hooks 只能在 ins 中调用...


NextJS 中 useFormStatus() 始终为 false

我尝试使用 useFormStatus() 在提交表单并等待获取数据时动态更改 UI。 我有一个像这样的表单组件 函数 onSubmit(数据:z.infer 我正在尝试使用 useFormStatus() 在提交表单并等待获取数据时动态更改 UI。 我有一个像这样的表单组件 function onSubmit(data: z.infer<typeof FormSchema>) { requestImg(data).then((imageStringify) => { const binaryData = Buffer.from(imageStringify.image); const imageBase64 = URL.createObjectURL( new Blob([binaryData.buffer], { type: "image/jpeg" } /* (1) */) ); setOpen(true); setSource(imageBase64); }); } if (isDesktop) { return ( <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6" > ... 其中 requestImg(data) 是服务器操作。 然后,我将 Button 组件嵌套在不同的 Button.tsx 文件中的 <form> 中 import { useFormStatus } from "react-dom"; import { Button } from "@/components/ui/button"; export default function ButtonSub() { const { pending } = useFormStatus(); console.log(pending); return ( <Button className="w-full" type="submit" aria-disabled={pending}> {pending ? "Processing..." : "Submit"} </Button> ); } 问题是,当我单击提交时,按钮文本不会更改为“正在处理...” 编辑 似乎仅当您在表单上使用操作关键字时才有效。我试过了 <form action={async (formData: FormData) => { requestImg(formData).then((imageStringify) => { const binaryData = Buffer.from(imageStringify.image); const imageBase64 = URL.createObjectURL( new Blob([binaryData.buffer], { type: "image/jpeg" } /* (1) */) ); setSource(imageBase64); setOpen(true); }); }} className="w-2/3 space-y-6" > 但是现在使用 byte8Array 生成的图像已损坏。 我有一个带有动态 src 的图像,其中充满了 const [source, setSource] = useState(""); <img src={source}/> 似乎只有在您使用 action 关键字时才有效 形式。 确实如此。 useFormStatus 必须在表单的子组件内使用,它可以监视服务器操作的状态变化。但据我所知,它会监听 action。 action 定义提交后表单数据的服务器端目的地。在服务器操作的上下文中,服务器操作向当前 URL 发出 post 请求。所以它没有监听表单 onSubmit,这就是为什么你的第一个代码执行不起作用。 现在服务器操作在服务器上下文中运行,它们在服务器上执行,但setState是客户端特定的代码


如果 markdown frontmatter 中的值(对于博客文章)键:值对是特定字符串,则运行 git hook

我有一个 git hook 预提交,如果文件在我的 AstroPaper 博客中被修改,它会更新 modDatetime。 # 修改文件,更新modDatetime git diff --cached --name-status | git diff --cached --name-status | git diff --cached --name-status | egrep -i &q...


如何编写 helm hook 来删除持久卷

我是 k8s 和 helm 的新手。我正在部署一个名为 zeebe 的开源分布式软件,它为 k8s 部署提供 helm 图表。我发现即使在执行 helm uninstall comm之后...


如何在不重新加载页面的情况下发送带有文件的表单?

我尝试在ajax中发送表单而不重新加载页面,但我看到,文件上的链接不存在...... 我有下一个表格: 我尝试在ajax中发送表单而不重新加载页面,但我看到,文件上的链接不存在... 我有下一个表格: <form id="settings" method="POST" enctype="multipart/form-data"> ... <input type="file" id="logo" style="display:none;" name="logo" accept="image/png, image/jpeg, image/gif"> <button type="submit" id="send" class="btn btn-primary">save</button> </form> Ajax 脚本: $('#settings').submit(function(e){ e.preventDefault(); var form = $(this).serialize(); alert(form); // file is not attached... $.ajax({ url : '/settings', type : 'POST', crossDomain : false, data : form, contentType : 'multipart/form-data', dataType : 'json', progressData: false, cache : false, success : function(r){ alert (111); } }).fail(function(){ console.log('Error occured!'); }); }); 在服务器端,我收到错误: org.apache.tomcat.util.http.fileupload.FileUploadException:请求被拒绝,因为未找到多部分边界 我尝试不序列化表单,而是写了 data : form -> data : new FormData(this) 此选项会导致错误“非法调用”。如何在不重新加载页面的情况下发送带有文件的表单? 要使用 AJAX 发送带有文件的表单而不重新加载页面,您需要使用 FormData 来正确处理文件上传。 <form id="settings" method="POST" enctype="multipart/form-data"> <!-- Other form fields --> <input type="file" id="logo" name="logo" accept="image/png, image/jpeg, image/gif"> <button type="submit" id="send" class="btn btn-primary">Save</button> </form> $(document).ready(function() { $('#settings').submit(function(e){ e.preventDefault(); var formData = new FormData(this); $.ajax({ url: '/settings', type: 'POST', data: formData, contentType: false, processData: false, cache: false, success: function(response){ alert('Form submitted successfully!'); // Handle the response from the server }, error: function(){ console.log('Error occurred!'); } }); }); });


如何在 Git-Bash 终端中读取用户输入并传递给 Python 脚本

在开始之前我只是想告诉大家我是Python的初学者:) 我正在通过 git bash 运行 python 脚本,同时提交代码更改(使用 git hook[commit-message]),我想阅读...


了解 WooCommerce 主题 - 使用我自己的主题

新闻: 在上面的答案之后,我可以再改变一点,但我仍然无法改变我需要的一切。现在最大的问题是: 如何删除操作(@hooked)的内容并将其放入新的hook中...


Acf用户:通过acf用户编号字段搜索用户

我正在尝试在管理屏幕中的用户中显示 ACF 字段,并且我能够实现这一点。现在我想在正常的 WordPress 用户搜索中通过这个 ACF 字段搜索用户。有没有 Hook / 代码片段...


“UserControlform”类型的值无法在 VB.NET 中转换为“Form”

我的“UserControl”表单中有错误 即在 BunifuSnackbar 中,但如果我在表单中使用它,则不会出现错误。 错误是“PgStockin”类型的值无法转换为“Form” 请指导我。 T...


ReactJS - 生成具有多个动态行的 ant.d 表单

我尝试使用 ReactJS 和 antd Form 创建 Form 表单中的每一行都需要根据用户在该行中第一个元素中的选择来呈现不同的元素(输入/选择) 参见图片


ASP.NET MVC 多选下拉列表

我使用以下代码让用户选择表单上的多个位置。 @Html.DropDownListFor(m => m.location_code, Model.location_type, new { @class = "form-control", @multiple = "mul...


有没有办法在从 Powershell 发布 api 调用时将表单数据转换为 x-www-form-urlencoded 格式?

我正在 VSCode 中编写 powershell 脚本。 当尝试将表单数据转换为 x-www-form-urlencoded 格式时,我不断遇到上述问题。 我有一个表单数据如下: $表单数据=@{ '


XHR 请求出现 500 内部服务器错误

这是我的代码: var fd = new FormData(document.querySelector('#form-step1')); var xhr = new XMLHttpRequest(); xhr.open('POST', '/Handlers/newAccount_handler.php', true); xhr.send(fd); // 这个我...


我无法打印onChange的值

从“react”导入React; 从“react-input-mask”导入InputMask; 从“./inputMask.module.scss”导入样式; 从“反应...


MatToolbar:尝试组合不同的工具栏模式

出现以下错误: MatToolbar:尝试组合不同的工具栏模式。显式指定多个 元素或仅将内容放置在 中 出现以下错误: MatToolbar:尝试组合不同的工具栏模式。要么显式指定多个 <mat-toolbar-row> 元素,要么仅将内容放置在单行的 <mat-toolbar> 中。 我的代码已经在 mat-toolbar 中应用了 mat-toolbar-row。然而,该错误仍然存在。 html文件的代码片段如下: <div class="wallpaper"> <mat-toolbar color="primary"> <mat-toolbar-row> <span>Welcome, User</span> <span class="example-fill-remaining-space"></span> <span class="align-center"></span> <span class="example-spacer"></span> <button mat-button>Create Incident </button> <a [routerLink]="['/closed']"><button mat-button style="color: white">Closed Incident</button></a> <span class="example-spacer"></span> <a [routerLink]="['/login']"><button mat-button>Logout</button></a> <img src="../../assets/hsbc_logo3.png" class="logo-hsbc"/> </mat-toolbar-row> <h1>INCIDENT MANAGEMENT SYSTEM</h1> </mat-toolbar> <h1>Welcome to Incident Management System</h1> <mat-card style="background: transparent"> <!-- Title of an Card --> <mat-card-title>Incident Details</mat-card-title> <mat-card-content> <form> <table > <tr> <td> <mat-form-field class="demo-full-width"> <mat-label >Description</mat-label> <textarea [(ngModel)]="incident.description" name="description" cdkTextareaAutosize cdkAutosizeMinRows="1" cdkAutosizeMaxRows="5" matInput></textarea> </mat-form-field> </td> <td> <h4>{{message}}</h4> </td> </tr> <tr> <td> <mat-form-field class="demo-full-width"> <input matInput [matDatepicker]="picker" placeholder="Incident Date" [(ngModel)]="incident.date" name="date" > <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle> <mat-datepicker touchUi="true" #picker></mat-datepicker> </mat-form-field> </td> </tr> <tr> <td colspan="2"> <mat-form-field class="demo-full-width"> <input matInput placeholder="Incident Category" [(ngModel)]="incident.category" name="category"> </mat-form-field> </td> </tr> <tr> <td > <mat-form-field class="demo-full-width"> <mat-select placeholder="Application Owner" [(ngModel)]="incident.owner" name="owner"> <mat-option style="background-color:grey">-- Select--</mat-option> <mat-option style="background-color:cornsilk" value="1">BRV</mat-option> <mat-option style="background-color:cornsilk" value="2">FRTB</mat-option> <mat-option style="background-color:cornsilk" value="3">FSA</mat-option> </mat-select> </mat-form-field> </td> <td> <mat-form-field> <mat-select placeholder="Symphony Group" [(ngModel)]="incident.symphony_group" name="symphony_group"> <mat-option style="background-color:grey">-- Select --</mat-option> <mat-option style="background-color:cornsilk" value="1">MMO SheHacks</mat-option> <mat-option style="background-color: cornsilk" value="2">MMO IT INDIA</mat-option> </mat-select> </mat-form-field> </td> </tr> <tr> <td> <mat-form-field> <mat-select placeholder="Application" [(ngModel)]="incident.application" name="application"> <mat-option style="background-color:grey">-- Select--</mat-option> <mat-option style="background-color:cornsilk" value="1">BRV</mat-option> <mat-option style="background-color:cornsilk" value="2">FRTB</mat-option> <mat-option style="background-color:cornsilk" value="3">FSA</mat-option> </mat-select> </mat-form-field> </td> <td> <mat-form-field> <mat-select placeholder="Status" [(value)]="status" [(ngModel)]="incident.status" name="status"> <mat-option style="background-color:grey">-- Select --</mat-option> <mat-option style="background-color: green" value="1">Available</mat-option> <mat-option style="background-color: orange" value="2">Reduced</mat-option> <mat-option style="background-color: red" value="3">Unavailable</mat-option> </mat-select> </mat-form-field> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" class="content-center"> <button style="margin:5px" mat-raised-button color="accent" (click)="submit()">Submit Incident</button> <button style="margin:5px" mat-raised-button color="accent" (click)="reset()">Clear</button> <button style="margin:5px" mat-raised-button color="accent">Raise BGCR</button> <button style="margin:5px" mat-raised-button color="accent">Raise Jira</button> </td> </tr> </table> </form> </mat-card-content> </mat-card> </div> 您需要移除 <h1>INCIDENT MANAGEMENT SYSTEM</h1> 或将其放入 <mat-toolbar-row> 内。 我无法在垫子工具栏中填充图像 有什么帮助吗?


从数据库中选择 SELECT 选项后如何显示/隐藏 DIV?

这是选择选项的代码; 这是选择选项的代码; <div class="modal-body row"> <form role="form" action="patient/addNew" class="clearfix" method="post" enctype="multipart/form-data"> <div class="form-group col-md-6"> <label for="exampleInputEmail1"><?php echo lang('categorie'); ?></label> <select class="form-control m-bot15" name="categorie" value='' id="p_category"> <option value="#"> Sélectionner catégorie</option> <?php foreach ($categories as $category) { ?> <option value="category"><?php if (!empty($setval)) { if ($category->category == set_value('category')) { echo 'selected'; } } if (!empty($patient->category)) { if ($category->category == $patient->category) { echo 'selected'; } } ?> > <?php echo $category->category; ?> </option> <?php } ?> </select> </div> 这是必须显示/隐藏的 div: <label for="exampleInputEmail1"><?php echo lang('name_Us'); ?></label> <input type="text" class="form-control" name="name_husband" id="nameUs" placeholder=""> <label for="exampleInputEmail1"><?php echo lang('number_pre'); ?></label> <input type="number" class="form-control" name="number_pre" id="nbreEnf" placeholder=""> </div> 这是 JavaScript 代码: $('.divUs').hide(); $(document.body).on('change', '#p_category', function () { var v = $("select.p_category option:selected").val() if (v == 'Fe_Ence') { $('.divUs').show(); } else { $('.divUs').hide(); } }); }); 我希望如果选择了元素(Fe_Ence),则可以显示 div,否则,它保持隐藏 例如,您可以使用 :has 选择器 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <div id="thingtohide"> <h1>Hello</h1> </div> <div id="checkbox"> <input type="checkbox"> </div> <style> body:has(#checkbox input:checked) #thingtohide { visibility: hidden; } </style> </body> </html> 因此,如果父元素有一个选中的复选框,那么您可以定位与该父元素不同的子元素。


表单响应:“无法处理请求 HTTP ERROR 500”。我做错了什么?

我尝试在网站上编写 php 表单,但收到错误 500。我无法弄清楚我做错了什么。你能看一下代码看看我做错了什么吗? PHP: 我尝试在网站上编写 php 表单,但收到错误 500。我无法弄清楚我做错了什么。你能看一下代码看看我做错了什么吗? PHP: <?php // define variables and set to empty values $name = $email = $phone = $enquiry = ""; if ( $_SERVER[ "REQUEST_METHOD" ] == "POST" ) { if ( empty( $_POST[ "name" ] ) ) { $nameErr = "Name is required"; } else { $name = test_input( $_POST[ "name" ] ); // check if name only contains letters and whitespace if ( !preg_match( "/^[a-zA-Z-' ]*$/", $name ) ) { $nameErr = "Only letters and white space allowed"; } } if ( empty( $_POST[ "email" ] ) ) { $emailErr = "Email is required"; } else { $email = test_input( $_POST[ "email" ] ); // check if e-mail address is well-formed if ( !filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { $emailErr = "Invalid email format"; } } if ( empty( $_POST[ "phone" ] ) ) { $comment = ""; } else { $comment = test_input( $_POST[ "phone" ] ); } if ( empty( $_POST[ "enquiry" ] ) ) { $comment = ""; } else { $comment = test_input( $_POST[ "enquiry" ] ); } } // Create the email and send the message $destination = "[email protected]"; $subject = "Website Contact Form Enquiry: $name"; $body = "You have received a new message from your website contact form.\\n\\n"."Here are the details:\\n\\nName: $name\\n\\nEmail: $email\\n\\nPhone: $phone\\n\\nEnquiry:\\n$enquiry"; $header = "From: [email protected]\\n"; $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; $headers[] = "From: " . $fromAddress; $headers[] = "Subject: " . $subject; $headers[] = "X-Mailer: PHP/".phpversion(); mail($destination, $subject, $message, implode("\r\n", $headers)); // mail($to,$subject,$msg,$headers); echo "Email successfully sent."; ?> HTML 格式: <form id="contact-form" method="post" action="/contact.php" role="form"> <div class="messages"></div> <div class="controls"> <div class="row"> <div class="col-md-10"> <div class="form-group"> <input id="form_name" type="text" name="name" class="form-control" placeholder="Name*" required="required" data-error="Your name is required." > <div class="help-block with-errors"></div> </div> </div> <div class="col-md-10"> <div class="form-group"> <input id="form_email" type="email" name="email" class="form-control" placeholder="Email*" required="required" data-error="Valid email is required." > <div class="help-block with-errors"></div> </div> </div> <div class="col-md-10"> <div class="form-group"> <input id="form_phone" type="text" name="phone" class="form-control" placeholder="Phone" > <div class="help-block with-errors"></div> </div> </div> </div> <div class="row"> <div class="col-md-10"> <div class="form-group"> <textarea id="form_enquiry" name="enquiry" class="form-control" placeholder="Enquiry*" rows="6" required="required" data-error="Please, leave us a message."></textarea> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-12"> <input class="btn btn-large btn-primary centre mt-10" type="submit" value="Submit" > </div> </div> </div> </form> 我已按照其他人的指示使表单正常工作,但所做的更改仍然会出现错误。 这是一个简单的形式,但我似乎对我做错了什么缺乏了解。 请帮助我。 如果您查看发送邮件的行,这是一个硬行结尾,将 $headers 推到新行上吗?这将调用 500 错误。 查看 /var/log/apache2/error.log(如果您使用的是 Debian)或 /var/log/httpd/error.log(如果使用的是 RHEL 或类似系统)。 您的代码存在许多问题,但首先关注快乐的道路,然后让事情正常运行。


从数据库表中选择选择选项后如何显示/隐藏隐藏的 Div?

以下是选择选项的代码: 这是选择选项的代码: <div class="modal-body row"> <form role="form" action="patient/addNew" class="clearfix" method="post" enctype="multipart/form-data"> <div class="form-group col-md-6"> <label for="exampleInputEmail1"><?php echo lang('categorie'); ?></label> <select class="form-control m-bot15" name="categorie" value='' id="p_category"> <option value="#"> Sélectionner catégorie</option> <?php foreach ($categories as $category) { ?> <option value="category"><?php if (!empty($setval)) { if ($category->category == set_value('category')) { echo 'selected'; } } if (!empty($patient->category)) { if ($category->category == $patient->category) { echo 'selected'; } } ?> > <?php echo $category->category; ?> </option> <?php } ?> </select> </div> 这是应该显示/隐藏的 Div: <div class="form-group col-md-6" id="divCacher" style="display: none"> <label for="exampleInputEmail1"><?php echo lang('name_husband'); ?></label> <input type="text" class="form-control" name="name_Us" id="nameUs" placeholder=""> <label for="exampleInputEmail1"><?php echo lang('number_pregnancy'); ?></label> <input type="number" class="form-control" name="number_pregnancy" id="nbreEnfants" placeholder=""> </div> 这是 JavaScript 代码: $(document).ready(function () { $('.divCacher').hide(); $(document.body).on('change', '#p_category', function () { var v = $("select.p_category option:selected").val() if (v == 'Fe_Ence') { $('.divCacher').show(); } else { $('.divCacher').hide(); } }); }); 我希望如果我们选择 Fe_Ence 类别,则 div 会显示,否则,它会保持隐藏 您需要将 $category 设置为选项值更改此: <option value="category"> 对此: <option value="<?=$category?>"> 以下是适用于更多此类情况的示例: <!--SELECT INPUT--> <select id="p_category"> <option value=""> Sélectionner catégorie</option> <?php foreach ($categories as $category): ?> <option value="<?=$category?>"><?=$category?> <?php endforeach;?> </select> <!--Container List--> <div class="cat-container" data-id="test1"> <h1>This is Test1 Category</h1> </div> <div class="cat-container" data-id="Fe_Ence"> <h1>This is Fe_Ence Category</h1> </div> <div class="cat-container" data-id="test3"> <h1>This is test3 Category</h1> </div> // Javascript code checkCategory(); $("#p_category").on('change', checkCategory) function checkCategory() { $('.cat-container').hide() const selected = $('#p_category').val() if (!selected) return; $(`[data-id=${selected}`).show() }


Angular Reactive Form - 验证在 formGroup 中不起作用

我定义了这个表单组 获取 createItem(): FormGroup { 返回 this.formBuilder.group({ 名称:['',验证器.required], 电子邮件:['',验证器.required], 手机:[...


addPointerPressed 和 addActionListener 有什么区别?

我有以下示例代码: hi = new Form("点击测试应用程序", BoxLayout.y()); Label l = new Label("按程序点击"); hi.add(l); b1 = 新按钮(“单击


从 Silverstripe BulkManager 添加和删除操作

向 modelAdmin 添加批量管理器,如下所示: 使用Colymba\BulkManager; FAQAdmin 类扩展了 ModelAdmin { 公共函数 getEditForm($id = null, $fields = null) { $form = 父级::getEd...


Angular Material 2:修复多行错误消息

我在我的角度应用程序中使用角度材料2。当我的表单输入字段错误消息超过一行时,我遇到了问题。这是照片: 这是代码: 我在我的角度应用程序中使用角度材料 2。当我的表单输入字段错误消息超过一行时,我遇到了问题。这是照片: 这是代码: <md-error *ngIf="password.touched && password.invalid"> <span *ngIf="password.errors.required"> {{'PASSWORD_RECOVERY.FIELD_REQUIRED' | translate}} </span> <span *ngIf="password.errors.minlength || password.errors.maxlength"> {{'PASSWORD_RECOVERY.PASSWORD_LENGTH' | translate}} </span> <span *ngIf="password.errors.pattern"> {{'PASSWORD_RECOVERY.FOR_A_SECURE_PASSWORD' | translate}} </span> </md-error> 我通过阅读 github 了解到,这是 Angular 2 材料中的一个错误。有人通过自定义解决方法成功解决了这个问题吗? 问题是类为 .mat-form-field-subscript-wrapper 的元素是 position: absolute,所以它不占用实际空间。 按照 xumepadismal 在 github 上关于此问题的建议,您可以添加此 scss 作为解决我的问题的解决方法: // Workaround for https://github.com/angular/material2/issues/4580. mat-form-field .mat-form-field { &-underline { position: relative; bottom: auto; } &-subscript-wrapper { position: static; } } 它会转换静态 div 中的 .mat-form-field-subscript-wrapper 节点,并将 .mat-form-field-unterline 重新定位在输入字段之后。 正如材料 15 中在 github 讨论中提到的,可以通过将 subscriptSizing="dynamic" 添加到 mat-form-field 来解决问题。 要更改默认行为,您必须使用以下选项更新 angular.module.ts 提供程序: providers: [ { provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: { subscriptSizing: 'dynamic' } } ] 这也可以在材料文档中找到 使用@mattia.corci提出的解决方案会导致错误消息被推到底部太多,从而在顶部留下不必要的空白空间。 使用 Tailwind CSS,这个解决方案对我来说适用于最新的 Angular 17: .mat-mdc-form-field { @apply w-full self-start; .mat-mdc-form-field-subscript-wrapper { @apply flex; .mat-mdc-form-field-error-wrapper { @apply static; } } } mat-form-field.ng-invalid.ng-touched { animation: example; animation-duration: 0.3s; margin-bottom: 20px; } @keyframes example { from { margin-bottom: 0; } to { margin-bottom: 20px; } } 它对我有用。


Angular 自定义验证控件无法获取表单值

我的 form-validators.ts 中的代码: console.log('密码:', 密码?.值); console.log('confirmPwd:',confirmPwd?.value); ...总是让我未定义,导致自定义验证(


向垫子表添加额外的行

所以我有一张垫子桌 所以我有一张垫子桌 <mat-table class="table" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="tableDrop($event)" [dataSource]="tableDataSource"> <ng-container *ngFor="let column of columns; let i = index" [matColumnDef]="column.name"> <mat-header-cell *matHeaderCellDef cdkDrag dkDragLockAxis="x" cdkDragBoundary="mat-header-row"> {{ column.title }} </mat-header-cell> <mat-cell *matCellDef="let element"> {{ element[column.name] }} </mat-cell> </ng-container> <mat-header-row class="tableHeader" *matHeaderRowDef="tableDisplayedColumns" #tableHeaderRow> </mat-header-row> <mat-row class="tableRow" *matRowDef="let row; columns: tableDisplayedColumns;" [class.selected-row]="tableSelectedRows.has(row)" (click)="selectUnselectRow(row)"> </mat-row> </mat-table> 但我需要在表标题下为相应的行过滤器添加一行。我尝试在标题和实际行声明之间添加 <mat-row> ,但是由于过滤器是不同的输入(例如数字、自动完成选择和多选),我无法 *ngFor 它们(而且我不是当然我是否能够) 编辑:忘记发布过滤器 HTML <div class="filterGroup"> <mat-form-field class="filterField"> <input matInput type="number" (keydown)="updateManualPage(1)" placeholder="Filter za param1" formControlName="filterParam1"> </mat-form-field> <mat-form-field class="filterField"> <input matInput (keydown)="updateManualPage(1)" placeholder="Filter za param2" formControlName="filterParam2" [matAutocomplete]="autoSingleSelect"> <mat-autocomplete #autoSingleSelect="matAutocomplete" class="filterSelect" panelClass="filterSelect"> <mat-option *ngFor="let option of dropdownSingleFilteredOptions | async" [value]="option.param2"> {{option.param2}} </mat-option> </mat-autocomplete> </mat-form-field> <mat-form-field class="filterField"> <mat-select class="filterMultiselect" placeholder="Filter za param3" formControlName="filterParam3" multiple panelClass="filterMultiselect"> <mat-option *ngFor="let option of tableDataSource.data" [value]="option.param3"> {{option.param3}} </mat-option> </mat-select> </mat-form-field> </div> 以及相关组件.ts tableDisplayedColumns: string[] = ['param1', 'param2', 'param3']; columns: any[] = [ { name: 'param1', title: 'Param1' }, { name: 'param2', title: 'Param2' }, { name: 'param3', title: 'Param3' } ]; 为了解决这个问题,我设法通过删除 *ngFor 并手动放入过滤器来做到这一点。 <mat-table class="table" cdkDropList cdkDropListOrientation="horizontal" (cdkDropListDropped)="tableDrop($event)" [dataSource]="tableDataSource"> <ng-container matColumnDef="param1"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param1 <mat-form-field class="filterField"> <input matInput type="number" (keydown)="updateManualPage(1)" placeholder="Filter" formControlName="filterParam1"> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param1}}</span> </mat-cell> </ng-container> <ng-container matColumnDef="param2"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param2 <mat-form-field class="filterField"> <input matInput (keydown)="updateManualPage(1)" placeholder="Filter" formControlName="filterParam2" [matAutocomplete]="autoSingleSelect"> <mat-autocomplete #autoSingleSelect="matAutocomplete" class="filterSelect" panelClass="filterSelect"> <mat-option *ngFor="let option of dropdownSingleFilteredOptions | async" [value]="option.param2"> {{option.param2}} </mat-option> </mat-autocomplete> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param2}}</span> </mat-cell> </ng-container> <ng-container matColumnDef="param3"> <mat-header-cell *matHeaderCellDef cdkDrag cdkDragLockAxis="x" cdkDragBoundary="mat-header-row" [cdkDragStartDelay]="100"> Param3 <mat-form-field class="filterField"> <mat-select class="filterMultiselect" placeholder="Filter" formControlName="filterParam3" multiple panelClass="filterMultiselect"> <mat-option *ngFor="let option of tableDataSource.data" [value]="option.param3"> {{option.param3}} </mat-option> </mat-select> </mat-form-field> </mat-header-cell> <mat-cell *matCellDef="let data"> <span>{{data.param3}}</span> </mat-cell> </ng-container> <mat-header-row class="tableHeader" *matHeaderRowDef="tableDisplayedColumns" #tableHeaderRow> </mat-header-row> <mat-row class="tableRow" *matRowDef="let row; columns: tableDisplayedColumns;" [class.selected-row]="tableSelectedRows.has(row)" (click)="selectUnselectRow(row)"> </mat-row> </mat-table>


Node.js/fastify 出现错误,不支持的媒体类型:application/x-www-form-urlencoded

考虑: 文件index.js fastify.get("/paynow", (请求, 回复) => { 让数据= { TXN_AMOUNT: '10', // 请求金额 ORDER_ID: 'ORDER_123455', // 任何唯一的订单 ID CUST_ID:'


无法在react-三纤维中导入dat.gui

对于使用react- Three-Fiber制作的项目,我导入了以下库: 从 '三' 导入 * 作为三; 从“react”导入 React, { Suspense, useState }; 导入 { 画布,useLoader }


Node.js/fFastify 出现错误:“不支持的媒体类型:application/x-www-form-urlencoded”

考虑: 文件index.js fastify.get("/paynow", (请求, 回复) => { 让数据= { TXN_AMOUNT: '10', // 请求金额 ORDER_ID: 'ORDER_123455', // 任何唯一的订单 ID 库斯...


绑定了formControlName后,如何在html中使用它?

我当前有问题的 html 部分是这样的 ... 我的 html 当前有问题的部分是这个 <div class="psi-list"> <div class="flex-row" *ngFor="let item of psiList; index as i"> <p class="row-psi">{{ item.psi }}</p> <button class="icon-btn" (click)="deletePsi(item.psi)"><i class="cil-trash"></i></button> <button class="icon-btn" (click)="item.toggle = !item.toggle"><i class="cil-pen-alt"></i></button> <form [formGroup]="psiEditForm" id="psi-edit-form" class="form-horizontal" [hidden]="!item.toggle"> <input class="psi-input" type="text" placeholder="Update PSI here..." [(ngModel)]="psiEdit" [ngClass]="{'is-valid': !checkControlValidation(psiEditForm.controls.psi) && psiEditForm.controls.psi.touched, 'is-invalid': checkControlValidation(psiEditForm.controls.psi)}" (keydown.enter)="!psiEditForm.controls.psi.invalid ? editPsi(item.psi) : clearPsiEdit()" formControlName="psi" /> <div class="help-block validation-warning" *ngIf="checkControlValidation(psiEditForm.controls.psi)"><i class="fa fa-exclamation fa-lg"></i>Please Enter a Valid 2 Letter PSI</div> </form> </div> </div> 我使用 formControlName“psi”将控件传递给 .ts 文件中的 checkControlValidation 方法。然而,这会导致功能问题。每当我在一个输入框中输入内容时,它都会将其输入到 *ngFor 中的所有输入框中。 当我将表单控件名称更改为这个时 - [formControlName]="item.psi" 它将名称绑定到与其相关的项目,因此理论上我可以通过它来解决我的问题。但是,当我将 psiEditForm.controls.psi 的所有实例更改为 psiEditForm.controls.item.psi 时,我收到很多 TS2339 错误。 我有什么想法可以使用它吗?抱歉,我知道这可能措辞很糟糕 尝试这样 <div class="psi-list"> <div class="flex-row" *ngFor="let item of psiList; index as i"> <p class="row-psi">{{ item.psi }}</p> <button class="icon-btn" (click)="deletePsi(item.psi)"><i class="cil-trash"></i></button> <button class="icon-btn" (click)="item.toggle = !item.toggle"><i class="cil-pen-alt"></i></button> <form [formGroup]="psiEditForm" id="psi-edit-form" class="form-horizontal" [hidden]="!item.toggle"> <input class="psi-input" type="text" placeholder="Update PSI here..." [(ngModel)]="psiEdit" [ngModelOptions]="{standalone: true}" [ngClass]="{'is-valid': !checkControlValidation(psiEditForm.controls.psi) && psiEditForm.controls.psi.touched, 'is-invalid': checkControlValidation(psiEditForm.controls.psi)}" (keydown.enter)="!psiEditForm.controls.psi.invalid ? editPsi(item.psi) : clearPsiEdit()" formControlName="psi" /> <div class="help-block validation-warning" *ngIf="checkControlValidation(psiEditForm.controls.psi)"> <i class="fa fa-exclamation fa-lg"></i>Please Enter a Valid 2 Letter PSI </div> </form> </div> </div>


为什么我导入 React 时服务器返回 MIME 类型为“text/html”?

这是我的js: 从'./node_modules/react'导入React; 从'./node_modules/react-dom'导入ReactDOM; 让 thePage = React.createElement( '主要的', 无效的, '哈哈' ); ReactDOM.render(thePage,


尽管已安装,但找不到模块“@tanstack/react-table”

我正在开发一个 TypeScript React 项目,我正在尝试从 columns.tsx 文件中的 @tanstack/react-table 导入 ColumnDef。 从“@tanstack/react-table”导入{ColumnDef}; 出口...


创建新的 React 应用程序时遇到麻烦

当我尝试创建一个新的 React 应用程序时,我收到以下错误消息, 安装软件包。这可能需要几分钟。安装中 React、react-dom 和带有 cra-temp 的 React-scripts...


在操作中检测到不可序列化的值(redux-toolkit)

在store中action的payload中,我使用File类型存储下载的文件,然后该文件将在saga中通过验证 const form = new FormData(); if (私钥 &&


react-testing-library:无法关闭 MUI Select 的下拉菜单

我有一个 SelectExample.js 从“react”导入 React, { useState }; 从“@mui/material”导入{InputLabel、MenuItem、FormControl、Select、Typography };> 导出默认fu...


如何使用 Bootstrap 5 将嵌入水平居中

我正在尝试使用上面的图像进行集中输入。我按照位置文档进行操作,但不知何故图像没有水平集中: 代码: 我正在尝试使用上面的图像进行集中输入。我按照位置文档进行操作,但不知何故图像没有水平集中: 代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Title --> <title>Title</title> <!-- Css --> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> </head> <body> <div class="container position-absolute top-50 start-50 translate-middle"> <embed class="logo" src="https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="Logo"> <form action="/streams" method="POST"> <div class="input-group"> <input class="form-control border-danger border-5" type="text" aria-describedby="start-button"> <button class="btn btn-danger" type="submit" id="start-button">Click</button> </div> </form> </div> </body> </html> 我尝试手动执行此操作并使用 display flex,但没有成功。 使用text-center链接 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Title --> <title>Title</title> <!-- Css --> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"> </head> <body> <div class="container text-center"> <embed class="logo " src="https://www.google.com.br/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" alt="Logo"> <form action="/streams" method="POST"> <div class="input-group"> <input class="form-control border-danger border-5" type="text" aria-describedby="start-button"> <button class="btn btn-danger" type="submit" id="start-button">Click</button> </div> </form> </div> </body> </html>


form_for 凤凰城问题

我是 Phoenix/Elixir 的新手,正在尝试制作一个小聊天应用程序。我遇到了一些困难,希望你能提供帮助。 这是我的代码 <%= f = form_for :chat, "#", id: "chat-form...


如何在 HTMX 中停止轮询? 286并不能阻止htmx继续轮询

根据 HTMX 文档,轮询应在收到响应代码 286 后停止。 鉴于此代码: 根据 HTMX 文档,轮询应在收到响应代码 286 后停止。 给出这段代码: <form id="board" hx-post="/xxx/start" hx-select="#board" hx-trigger="every 1ms" hx-swap="outerHTML" > 我的服务器响应 286 代码: 为什么它继续 ping 我的服务器? 在旧的 reddit 线程中找到答案 顺便说一下,我使用 hx-swap:outerHTML 遇到了一个问题,其中 286 状态代码没有停止轮询,因为 hx 元素是刷新的一部分。我想我可以在里面嵌套另一个 div 并选择该元素来修复这个问题。 回想起来,这很有意义。 解决方案: <form id="board" hx-post="/xxx/start" hx-trigger="every 500ms" hx-select="#board-content" hx-target="#board-content" hx-swap="outerHTML" > <div id="gameoflife-board-content"> // rest of form </div> </form>


在React版本18中使用react-facebook-login

我希望将react-facebook-login库与React版本18一起使用,但我无法安装该包。 npm 在控制台上抛出错误? 该库是否支持 Reac 18 版本...


使用php以动态形式考虑用户输入

考虑我有一个像这样的简单表格: 考虑我有一个像这样的简单表格: <form method="post" action="index.php"> <input id='textsearch' type="text" placeholder="Enter a character" name="search"> <button onclick="addfields()">Add</button> </form> 此处,当用户单击“添加”按钮时,会触发 onclick 事件并激活 addfields() 功能。在该函数中,我设法在此表单中添加一个输入字段,表单现在如下所示: <form method="post" action="index.php"> <input id='textsearch' type="text" placeholder="Enter a character" name="search"> <input id='textsearch_1' type="text" placeholder="Enter a character" name="search_1"> <button onclick="addfields()">Add</button> </form> 但是,出现了一个问题。如果我使用 php 来访问这些变量,我可以使用这样的东西: <?php $first_char=$_POST["search"]; $second_char=$_POST["search_1"]; ?> 但是它到哪里结束呢?我事先不知道用户创建了多少字段并在这些字段中输入了数据。那么有什么办法可以解决呢? 注意:我知道许多用户不赞成使用 onclick() 功能。我仍然坚持这个不好的使用习惯。对此表示歉意。谢谢。 你可以尝试这个概念 HTML 表单 <form method="post" action="index.php"> <input id='textsearch' type="text" name="search[]"> <input id='textsearch_1' type="text" name="search[]"> <button onclick="addfields()">Add</button> </form> PHP <?php $search_text_array=$_POST["search"]; print_r($search_text_array); ?> 你应该得到这个 PHP 结果 Array ( [0] => textsearch [1] => textsearch_1 ) 在此示例中,javascript 使用onclick() 不相关,但解释如何获取 PHP 部分


浏览器将内容类型设置为 application/x-www-form-urlencoded

我为每个 @PostMapping 引用 @CrossOrigin(origin = “*”) 创建了一个注释。一开始我遇到了 415 错误,现在遇到了 503 错误以及应用程序的内容类型...


如何在 EAS 构建中使用 React Native Reanimated?

我按照react-native-reanimated文档的安装说明创建了两次相同的应用程序https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/ge...


React-select:虚拟化选项列表

在最新版本的react-select(3.1.0)中虚拟化选项列表的预期方式是什么? 有react-virtualized-select,但不再支持。谢谢。


© www.soinside.com 2019 - 2024. All rights reserved.