简体   繁体   English

在带有羊驼毛的阵列中使用颜色选择器?

[英]Using a colorpicker in an array with Alpaca?

I have been trying to use a colorpicker in an array (using Alpaca ) without success. 我一直试图在数组中(使用使用颜色拾取Alpaca )没有成功。

This may be my "issue" but I've been wrestling with it for a few hours now and I am stumped. 这可能是我的“问题”,但是我已经为之奋斗了几个小时,而我为此感到困惑。 I've got a stripped down jsfiddle here which demonstrates the issue: I am able to create a colorpicker – but the same code does not work when in an array. 我在这里得到了一个精简的jsfiddle 它演示了这个问题:我能够创建一个颜色选择器-但是当在数组中时,相同的代码不起作用。

Am I misunderstanding what an Alpaca array field can contain? 我是否误解了Alpaca数组field可以包含什么?


Example code from the jsfiddle: jsfiddle中的示例代码:

  var test = {
  view: 'bootstrap-edit-horizontal',
  schema: {
    "title": "Can't put a color picker in array?",
    "type": "object",
    "properties": {
      "testColorPicker": {
        "type": "string",
        "default": "#ff0000"
      },
      "categories": {
        "type": "array",
        "items": {
          "title": "Category",
          "type": "object",
          "properties": {
            "categoryID": {
              "type": "string",
              "title": "Category ID"
            },
            "categoryColor": {
              "type": "string",
              "title": "Where is my color picker?"
            }
          }

        }
      }
    }
  },
  options: {
    fields: {
      "testColorPicker": {
        "type": "colorpicker",
        "label": "Test Color"
      },
      "category": {
        "type": "object",
        "items": {
          "categoryID": {
            "label": "Category ID"
          },
          "categoryColor": {
            "type": "colorpicker",
            "label": "Category Color"
          }
        }
      }
    }
  }
};

$('#form').alpaca(test);

Finally figured this out. 终于想通了。 Wish there was aa more active Alpaca dev community and that the documentation was just a little bit more detailed about how options and views should be structured and how to specify parameters for fields like colorpicker . 希望有一个更加活跃的Alpaca开发社区,并且该文档稍微详细了关于应该如何构建optionsviews以及如何为colorpicker等字段指定参数。

Anyway: working fiddle: https://jsfiddle.net/ut8wgtk5/60/ 无论如何:正在工作的小提琴: https//jsfiddle.net/ut8wgtk5/60/

var data = {
    view: {
        "parent": "bootstrap-edit-horizontal"
    },
    schema: {
        "title": "Test",
        "type": "object",
        "properties": {
            "testColorPicker": {
                "type": "string",
                "default": "#000000"
            },
            "testSummernote": {
                "type": "string"
            },

            "testArray": {
                "type": "array",
                "title": "Array",
                "items": {
                    "title": "Array Item",
                    "type": "object",
                    "properties": {
                        "categorySummernote": {
                            "type": "string",
                        },
                        "categoryColor": {
                            "type": "string",
                            "default": "#000000"
                        }
                    }
                },
            }

        }
    },
    options: {
        "fields": {
            "testColorPicker": {
                "type": "colorpicker",
                "component": true,
                "label": "Test Color",
                useAlpha: false
            },
            "testSummernote": {
                "label": "Test Summernote",
                "type": "summernote",
                "summernote": {
                    "toolbar": [
                        ['style', ['bold', 'italic', 'underline', 'clear']],
                        ['font', ['strikethrough', 'superscript', 'subscript']],
                        ['fontsize', ['fontsize']],
                        ['color', ['color']],
                        ['para', ['ul', 'ol', 'paragraph']],
                        ['height', ['height']]
                    ]
                }
            },
            "testArray": {
                "toolbarSticky": true,
                "actionbarStyle": "bottom",
                "label": "Array",
                "items": {
                    "fields": {
                        "categorySummernote": {
                            "label": "Test Summernote",
                            "type": "summernote",
                            "summernote": {
                                "toolbar": [
                                    ['style', ['bold', 'italic', 'underline', 'clear']],
                                    ['font', ['strikethrough', 'superscript', 'subscript']],
                                    ['fontsize', ['fontsize']],
                                    ['color', ['color']],
                                    ['para', ['ul', 'ol', 'paragraph']],
                                    ['height', ['height']]
                                ]
                            }
                        },
                        "categoryColor": {
                            "type": "colorpicker",
                            "component": true,
                            "label": "Test Color"
                        }
                    }
                }
            }
        }
    }
};

$('#form').alpaca(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM