# フォームブリッジ で本日から１ヶ月以上後の日付しか選択できないようにする

**URL:** <https://community.cybozu.dev/t/topic/3212>\
**Category:** kintone 開発相談\
**Created:** [2018 年 7 月 17 日午前 1:24 UTC](https://community.cybozu.dev/t/topic/3212 "2018-07-17T01:24:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account775](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@Legacy\_Account775](https://community.cybozu.dev/u/Legacy_Account775)\
**Post date:** [2018 年 7 月 17 日午前 1:24 UTC](https://community.cybozu.dev/t/topic/3212/1 "2018-07-17T01:24:24Z")

</div>

初心者で恐縮なのですが、  
フォームブリッジで質問があります。

「解約日」という日付選択フォームがありまして、  
今日から１ヶ月以上後の日付しか選択できないようにしたいです。

例えば今日が７月１７日だとすると、  
解約日は８月１８日以降しか選択できない、という具合です。

（１ヶ月後と書きましたが、  
３０日後でも３１日後でも問題ありません）

&nbsp;

現状ではこのようなことが  
可能なのどうかもわかりません。  
恐れ入りますがご教授のほどよろしくお願い致します。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account616](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@Legacy\_Account616](https://community.cybozu.dev/u/Legacy_Account616)\
**Post date:** [2018 年 7 月 17 日午前 7:40 UTC](https://community.cybozu.dev/t/topic/3212/2 "2018-07-17T07:40:23Z")

</div>

方法としては2通りあるかと思います。

機能で日付の期間バリデーションがあるかと思います。

設定すると state にある fields の該当 field に validations が追加されます。

このfb.events.form.created イベントでバリデーションのパラメータを変更することで、30日後のバリデーションが可能かと思います。

```
var d = new Date();
d.setDate(d.getDate() + 30);fields[0].validations[0].params[1] = d.getYear() + '-' + (d.getMonth()+1) + '-' + d.getDate();

```

&nbsp;

しかし、この方法だとバリデーションメッセージが固定のものとなるため、変更したくなるかと思います。

その場合、任意のバリデーションを追加することができます。

任意のバリデーションを追加し、解約日フィールドにバリデーションを追加することで機能します。

&nbsp;

参考 [https://fb.kintoneapp.com/user/customize.html](https://fb.kintoneapp.com/user/customize.html)

&nbsp;

以上、参考になりますでしょうか？

---

<div class="post-metadata">

**Author:** ![Legacy\_Account775](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@Legacy\_Account775](https://community.cybozu.dev/u/Legacy_Account775)\
**Post date:** [2018 年 7 月 22 日午前 11:52 UTC](https://community.cybozu.dev/t/topic/3212/3 "2018-07-22T11:52:59Z")

</div>

ありがとうございます。  
いろいろ試してみたのですが、完全に行き詰まっています。

①JavaScriptでファイル（拡張子がjs）を作成してアップロードしたのですが、  
そもそも読み込まれてないようです。

作成したファイルは以下画像です。  
（alartで読み込まれたかどうかチェックしてます）

②初歩的な質問になるかもしれないのですが、  
fields[0]←このカッコ内の数字は何を指しているのでしょうか？

&nbsp;

以上ご回答いただけると幸いです。  
何卒よろしくお願い申し上げます。

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account616](https://avatars.discourse-cdn.com/v4/letter/l/b5e925/32.png) [@Legacy\_Account616](https://community.cybozu.dev/u/Legacy_Account616)\
**Post date:** [2018 年 7 月 23 日午前 12:04 UTC](https://community.cybozu.dev/t/topic/3212/4 "2018-07-23T00:04:58Z")

</div>

fb.events.form.created イベントで、console.log(state.fields) をしてみると、そのフォームの全フィールドが配列の形式で確認することができます。

目的のフィールドが配列のどの位置にあるか確認して、fields[n] の n を決めます。

上記のコードでは、一番上のフィールドに対して custom\_validation1 を追加するコードになっています。

&nbsp;

以上、参考になりますでしょうか？

---

<div class="post-metadata">

**Author:** ![Legacy\_Account775](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@Legacy\_Account775](https://community.cybozu.dev/u/Legacy_Account775)\
**Post date:** [2018 年 7 月 23 日午後 2:30 UTC](https://community.cybozu.dev/t/topic/3212/5 "2018-07-23T14:30:17Z")

</div>

ありがとうございます。

無事にできました！

---

<div class="post-metadata">

**Author:** ![Legacy\_Account548](https://avatars.discourse-cdn.com/v4/letter/l/ee7513/32.png) [@Legacy\_Account548](https://community.cybozu.dev/u/Legacy_Account548)\
**Post date:** [2023 年 1 月 4 日午前 4:43 UTC](https://community.cybozu.dev/t/topic/3212/6 "2023-01-04T04:43:56Z")

</div>

こちらを参考にして日付入力に同様の設定をして大変便利に使わせていただいているのですが、別のjavascriptを設定するとどちらの制御もきかなくなってしまうため、質問させていただいてもよろしいでしょうか。

&nbsp;

1つ目「日付を2日後より後のみ入力できる」

(function () {

&nbsp; &nbsp; ‘use strict’;

&nbsp; &nbsp; fb.events.form.created.push(function (state) {  
&nbsp; &nbsp; &nbsp; &nbsp; state.fields[n].validations.push({  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params: [],  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rule: ‘custom\_validation1’  
&nbsp; &nbsp; &nbsp; &nbsp; });  
&nbsp; &nbsp; &nbsp; &nbsp; return state;  
&nbsp; &nbsp; });

&nbsp; &nbsp; fb.addValidators = function (state) {  
&nbsp; &nbsp; &nbsp; &nbsp; return {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; custom\_validation1: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; getMessage: function (日付, params) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ‘2 days later or more’;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validate: function (value, params) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; const min = new Date();  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; min.setDate(min.getDate() +1);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return value \> min;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; };  
&nbsp; &nbsp; };  
})();

&nbsp;

&nbsp;

2つ目「メールアドレスをルックアップ（4か所）フィールドにコピー」

(function() {  
&nbsp; “use strict”;

&nbsp; fb.events.form.created = [function (state) {  
&nbsp; &nbsp; state.record[‘lookup01’].value = state.record[‘\_\_kintoneAppAuthenticationEmail\_\_’].value;&nbsp;  
&nbsp; &nbsp; state.record[‘lookup02’].value = state.record[‘\_\_kintoneAppAuthenticationEmail\_\_’].value;&nbsp;  
state.record[‘lookup03’].value = state.record[‘\_\_kintoneAppAuthenticationEmail\_\_’].value;&nbsp;  
&nbsp; &nbsp; state.record[‘lookup04’].value = state.record[‘\_\_kintoneAppAuthenticationEmail\_\_’].value;&nbsp;  
/\*メールアドレスをルックアップフィールドにコピー\*/

&nbsp; &nbsp; return state;  
&nbsp; }];  
})();

&nbsp;

&nbsp;

上記の2つとも動くようにしたいです。  
勉強不足で恐縮ですが、アドバイスいただけますと幸甚です。  
どうぞよろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [2023 年 10 月 3 日午前 5:23 UTC](https://community.cybozu.dev/t/topic/3212/7 "2023-10-03T05:23:20Z")

</div>

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
