<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hajime</title>
    <description>The latest articles on DEV Community by hajime (@motamota).</description>
    <link>https://dev.to/motamota</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F51643%2F6f768973-65a2-4ef1-ace0-2bb1f55e516e.JPG</url>
      <title>DEV Community: hajime</title>
      <link>https://dev.to/motamota</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/motamota"/>
    <language>en</language>
    <item>
      <title>An autocomplete select input using shadcn/ui+react-hook-form+zod.</title>
      <dc:creator>hajime</dc:creator>
      <pubDate>Sat, 16 Mar 2024 12:04:05 +0000</pubDate>
      <link>https://dev.to/motamota/an-autocomplete-select-input-using-shadcnuireact-hook-formzod-17g1</link>
      <guid>https://dev.to/motamota/an-autocomplete-select-input-using-shadcnuireact-hook-formzod-17g1</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;simple answer: &lt;br&gt;
&lt;a href="https://www.armand-salle.fr/post/autocomplete-select-shadcn-ui"&gt;https://www.armand-salle.fr/post/autocomplete-select-shadcn-ui&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Additional Implementations
&lt;/h1&gt;

&lt;p&gt;Hi,I am currently developing a site called placeof.app and needed to add few things to above implementation like "Changes to the suggest logic""Validating the value with the key’s attribute""i18n". Here is how I did it. I hope it helps.&lt;/p&gt;
&lt;h2&gt;
  
  
  Changes to the suggest logic
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://ui.shadcn.com/docs/components/combobox"&gt;Combobox&lt;/a&gt; of shadcn/ui used in the above implementation is a wrapped version of &lt;a href="https://github.com/pacocoursey/cmdk/"&gt;cmdk&lt;/a&gt;’s Combobox. I wanted to change the logic of suggest, so I added my own implementation to the filter as described in cmdk’s documentation. It seems that sorting is also possible. &lt;br&gt;
For example,change &lt;a href="https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L88"&gt;https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L88&lt;/a&gt; to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;CommandPrimitive
  filter={(value, search) =&amp;gt; {
    if (value.includes(search)) return 1
    return 0
  }}
...
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Validating the value with the key’s attribute
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Add key
&lt;/h3&gt;

&lt;p&gt;There are two forms, key and value, and this is the implementation when you need to validate the value with the value of the key. When the key to suggest is confirmed by &lt;code&gt;handleKeyDown&lt;/code&gt; or other, it calls the parent component’s function with &lt;code&gt;onValueChange&lt;/code&gt;, and at that time,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; onValueChange={(key: SuggestKey) =&amp;gt; {
    form.setValue("suggestKeyId", key.suggestKeyId)
    form.setValue("suggestValueType", key.valueType)
}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the &lt;code&gt;setValue&lt;/code&gt; function of react-hook-form to add the confirmed key to the form. At this time, the react-hook-form is defined like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  type Inputs = z.infer&amp;lt;typeof SuggestKeyFormSchema&amp;gt;
  const form = useForm&amp;lt;Inputs&amp;gt;({
    resolver: zodResolver(SuggestKeyFormSchema),
    defaultValues: defaultValues,
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Processing when adding a value
&lt;/h3&gt;

&lt;p&gt;Register the value as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;FormItem&amp;gt;
      &amp;lt;FormControl&amp;gt;
        {specKey?.valueType === SpecValueType.TEXTAREA ? ((
          &amp;lt;Input
            aria-invalid={!!form.formState.errors.value}
            {...form.register("value")}
          /&amp;gt;
        )}
      &amp;lt;/FormControl&amp;gt;
    &amp;lt;/FormItem&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And validate using zod’s superRefine as follows. The valueType added when the key is added is used at this time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const SuggestKeyFormSchema = z
  .object({
    suggestKeyId: z.string().min(1),
    valueType: SuggestValueTypeSchema,
    value: z.string().min(1),
  })
  .superRefine((values, ctx) =&amp;gt; {
    if (
      values.valueType === SuggestValueTypeSchema.STRING &amp;amp;&amp;amp;
      values.value.length &amp;gt;= 20
    ) {
      ctx.addIssue({
        message: "need to be less than 20 words",
        code: z.ZodIssueCode.custom,
        path: ["value"],
      })
    }

   ....
  })
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  i18n
&lt;/h2&gt;

&lt;p&gt;By the way, the key is displayed by referring to the i18n file.&lt;/p&gt;

&lt;p&gt;Conversion location for the suggest list &lt;a href="https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L36"&gt;https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L36&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Conversion location for the confirmed key &lt;a href="https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L128"&gt;https://github.com/armandsalle/my-site/blob/main/src/components/autocomplete.tsx#L128&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;My special thanks to Armand. &lt;/p&gt;

</description>
      <category>form</category>
      <category>tailwindcss</category>
      <category>react</category>
    </item>
    <item>
      <title>裁判のIT化</title>
      <dc:creator>hajime</dc:creator>
      <pubDate>Sat, 30 Dec 2017 01:46:24 +0000</pubDate>
      <link>https://dev.to/motamota/it-25c5</link>
      <guid>https://dev.to/motamota/it-25c5</guid>
      <description>&lt;p&gt;裁判のIT化が始まるみたいです。&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.kantei.go.jp/jp/singi/keizaisaisei/saiban/index.html"&gt;https://www.kantei.go.jp/jp/singi/keizaisaisei/saiban/index.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;どのような結果になるか、楽しみです。&lt;/p&gt;

</description>
      <category>legal</category>
      <category>裁判</category>
    </item>
    <item>
      <title>裁判のIT化で注目したい10のこと</title>
      <dc:creator>hajime</dc:creator>
      <pubDate>Sat, 30 Dec 2017 01:44:34 +0000</pubDate>
      <link>https://dev.to/motamota/it10-2dmh</link>
      <guid>https://dev.to/motamota/it10-2dmh</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;1. テレビ裁判やVR裁判などの新しい裁判&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2. 新しい裁判に於ける「裁判の公開」「傍聴」のあり方&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3. スマートコントラクトと「執行」API&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4. 本人訴訟の定型化とクラウドファンディング&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;5. Virtual Data Roomやデジタルフォレンジックやデイスカバリ―制度の展開&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;6. VALCRI的新しい捜査手法&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;7. 裁判官の「働き方改革」と成果の計測&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;8. 裁判資料と機械学習の行方&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;9. ビックデータと個人情報に関する社会的合意&lt;/strong&gt;
&lt;/h2&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;10. 機械学習の正解データとしての司法統計と書記官の重要性&lt;/strong&gt;
&lt;/h2&gt;

</description>
      <category>裁判</category>
      <category>legal</category>
      <category>legaltech</category>
    </item>
  </channel>
</rss>
