SilverStripe - limiting the number of many relations a dataobject can have

前端 未结 3 1523
别那么骄傲
别那么骄傲 2021-01-20 06:33

If I have a $has_many relationship that I want to manage with a GridField in the cms, how would I go about putting a limit on the number of how man

3条回答
  •  旧巷少年郎
    2021-01-20 06:58

    I have wrote a quick jQuery plugin to limit the number of items a GridField can have: -

    Download the plugin here: - gridfieldlimit.js

    https://letscrate.com/f/monkeyben/silverstripe/gridfieldlimit.js

    Set up the plugin in the getCMSFields function: -

    // Pass GridField configs, each one containing field name and item limit
    $vars = array(
        "GridFieldLimits" => "[['GRIDFIELD_NAME_1', 3], ['GRIDFIELD_NAME_2', 6]]",
    );
    
    // Load the jquery gridfield plugin
    Requirements::javascriptTemplate("themes/YOUR_THEME_NAME/javascript/gridfieldlimit.js", $vars);
    

提交回复
热议问题