在netsuite中制作单选按钮

问题描述 投票:0回答:1

我目前正在尝试在netsuite中制作单选按钮,我很难找到好的资源来寻求帮助。有人经历过这个过程吗?

html netsuite
1个回答
0
投票

您无法官方使用 UI 自定义将自定义单选字段添加到 NetSuite 表单,它们仅在 SuiteScript 中可用。

想要使用 NetSuite 表单自定义添加单选按钮吗? 在这里查看我的新问题/答案!

仅当使用 SuiteScript 1 或 SuiteScript 2 中的

nlobjForm
对象时才支持单选字段。

官方代码示例(SuiteScript 1):

function radioButtonSamples(request, response)
{
var form = nlapiCreateForm('Sample Form');

// create a field of type 'label' - this field type holds no data and is used for display purposes only
form.addField('orgtypelabel','label','What type of organization are you?').setLayoutType('startrow');

/* add fields of type 'radio'. Notice that this set of radio buttons all specify 'orgtype' as the field
* name for each button. Each radio button is distinguished by the value specified in
* the 'source' parameter. By default, this set of radio fields will appear vertically since
* no layout type has been specified
*/
form.addField('orgtype', 'radio', 'Business To Consumer', 'b2c');
form.addField('orgtype', 'radio','Business To Business','b2b');
form.addField('orgtype', 'radio','Non-Profit','nonprofit');

//default the "Business to Business" radio button as selected when the page loads
form.getField('orgtype', 'b2b' ).setDefaultValue( 'b2b' );

/* now add the second set of radio buttons. Notice that this group also shares the same
* value for name, which is 'companysize'. Also note the use of the setLayoutType method.
* Use this when you want to position the buttons horizontally.
*/
form.addField('companysizelabel','label','How big is your organization?').setLayoutType('startrow');
form.addField('companysize', 'radio','Small (0-99 employees)', 's').setLayoutType('midrow');
form.addField('companysize', 'radio','Medium (100-999 employees)','m').setLayoutType('midrow');
form.addField('companysize', 'radio','Large (1000+ employees)','l').setLayoutType('endrow');

response.writePage( form );
}

以上代码重构为 SuiteScript 2.0:

/**
 * @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget'], function (serverWidget) {
    function onRequest(context) {

        var form = serverWidget.createForm({
            title: 'Sample Form'
        });

        // create a field of type 'label' - this field type holds no data and is used for display purposes only
        form.addField({
            id: 'orgtypelabel',
            label: 'What type of organization are you?',
            type: serverWidget.FieldType.LABEL
        }).updateLayoutType({
            layoutType: serverWidget.FieldLayoutType.STARTROW
        });

        /* add fields of type 'radio'. Notice that this set of radio buttons all specify 'orgtype' as the field
        * name for each button. Each radio button is distinguished by the value specified in
        * the 'source' parameter. By default, this set of radio fields will appear vertically since
        * no layout type has been specified
        */
        form.addField({
            id: 'orgtype',
            label: 'Business To Consumer',
            type: serverWidget.FieldType.RADIO,
            source: 'b2c'
        });
        form.addField({
            id: 'orgtype',
            label: 'Business To Business',
            type: serverWidget.FieldType.RADIO,
            source: 'b2b'
        });
        form.addField({
            id: 'orgtype',
            label: 'Non-Profit',
            type: serverWidget.FieldType.RADIO,
            source: 'nonprofit'
        });

        //default the "Business to Business" radio button as selected when the page loads
        form.updateDefaultValues({
            values: { orgtype: 'b2b' }
        })

        /* now add the second set of radio buttons. Notice that this group also shares the same
        * value for name, which is 'companysize'. Also note the use of the setLayoutType method.
        * Use this when you want to position the buttons horizontally.
        */
        form.addField({
            id: 'companysizelabel',
            label: 'How big is your organization?',
            type: serverWidget.FieldType.LABEL
        }).updateLayoutType({
            layoutType: serverWidget.FieldLayoutType.STARTROW
        });
        form.addField({
            id: 'companysize',
            label: 'Small (0-99 employees)',
            type: serverWidget.FieldType.RADIO,
            source: 's'
        }).updateLayoutType({
            layoutType: serverWidget.FieldLayoutType.MIDROW
        });
        form.addField({
            id: 'companysize',
            label: 'Medium (100-999 employees)',
            type: serverWidget.FieldType.RADIO,
            source: 'm'
        }).updateLayoutType({
            layoutType: serverWidget.FieldLayoutType.MIDROW
        });
        form.addField({
            id: 'companysize',
            label: 'Large (1000+ employees)',
            type: serverWidget.FieldType.RADIO,
            source: 'l'
        }).updateLayoutType({
            layoutType: serverWidget.FieldLayoutType.ENDROW
        });

        context.response.writePage(form);
    }
    return {
        onRequest: onRequest
    };
});

结果:

官方参考(SuiteScript 1):https://system.netsuite.com/app/help/helpcenter.nl?fid=section_n3144618.html#bridgehead_N3149879

© www.soinside.com 2019 - 2024. All rights reserved.