このブログは、旧・はてなダイアリー「檜山正幸のキマイラ飼育記 メモ編」(http://d.hatena.ne.jp/m-hiyama-memo/)のデータを移行・保存したものであり、今後(2019年1月以降)更新の予定はありません。

今後の更新は、新しいブログ http://m-hiyama-memo.hatenablog.com/ で行います。

型からフォームの生成

http://d.hatena.ne.jp/m-hiyama/20101213/1292201095 から再掲:


/**
* ランチの注文
*/
type LunchOrder = {
/** 会員識別情報 */
"ident" : {
"name" : string,
"memberNum" : integer
},
/** 今日の注文 */
"order" : {
"mainDish" : (
"special"|
"fish"|
"meat"
),
"drink" : (
"teaHot"|
"teaIce"|
"coffeeHot"|
"coffeeIce"
),
"dessert" : (
"pudding"|
"strawberryShortcake"|
"bavarianCream"|
"gateauChocolat"
)
}
};

[追記]以下のXMLはよくない、メンドクサイから直さないが、あとで別な形式を考える。 [/追記]

概念的には:

<form name="lunchOrder">
  <group name="ident" lable="ident" >
    <input ui="textField" name="ident.name" label="name" />
    <input ui="textField" name="ident.memberId" label="memberId" />
  </group>

  <group name="order" label="order" >
    <select name="order.mainDish" ui="checkboxGroup" label="mainDish">
      <option ui="radio" name="order.mainDish" value="special" label="special" />
      <option ui="radio" name="order.mainDish" value="fish"    label="fish"/> 
      <option ui="radio" name="order.mainDish" value="meat"    label="meat" />
      meat
    </select>

    <select name="order.drink" ui="radioGroup" label="drink">
      <option ui="radio" name="order.drink" value="teaHot"    label="teaHot" />
      <option ui="radio" name="order.drink" value="teaIce"    label="teaIce" />
      <option ui="radio" name="order.drink" value="coffeeHot" label="coffeeHot" />
      <option ui="radio" name="order.drink" value="coffeeIce" label="coffeeIce" />
    </select>

    <!-- 省略 -->

  </group>
</form>
<form method="post" action="lunchOrder.cgi">
  <fieldset id="ident"><legend>ident</legend>
    <div class="textField" id="ident.name">
      name:<input type="text" name="ident.name">
    </div>
    <div class="textField" id="ident.memberId">
      memberId:<input type="text" name="ident.memberId">
    </div>
  </fieldset>

  <fieldset id="order"><legend>order</legend>
    <div class="checkboxGroup" id="order.mainDish">
      mainDish:
      <input type="radio" name="order.mainDish" value="special" />
      special
      <input type="radio" name="order.mainDish" value="fish" /> 
      fish
      <input type="radio" name="order.mainDish" value="meat" />
      meat
    </div>

    <div class="radioGroup" id="order.drink">
      drink:
      <input type="radio" name="order.drink" value="teaHot" />
      teaHot
      <input type="radio" name="order.drink" value="teaIce" />
      teaIce
      <input type="radio" name="order.drink" value="coffeeHot" />
      coffeeHot
      <input type="radio" name="order.drink" value="coffeeIce" />
      coffeeIce
    </div>

    <div class="checkboxGroup" id="order.dessert">
      dessert:
      <input type="checkbox" name="order.dessert" value="pudding" />
      pudding
      <input type="checkbox" name="order.dessert" value="strawberryShortcake" />
      strawberryShortcake
      <input type="checkbox" name="order.dessert" value="bavarianCream" />
      bavarianCream
      <input type="checkbox" name="order.dessert" value="gateauChocolat" />
      gateauChocolat
    </div>
  </fieldset>

  <p><input disabled type="submit" value="送信する"></p>

</form>