แชร์ผ่าน


getFormContext (การอ้างอิง API ไคลเอ็นต์)

ส่งกลับการอ้างอิงไปยังแบบฟอร์มหรือหน่วยข้อมูลบนแบบฟอร์ม โดยขึ้นอยู่กับตําแหน่งที่ถูกเรียกเมธอด

ไวยากรณ์

ExecutionContextObj.getFormContext()

ค่าที่ส่งกลับ

ประเภท: วัตถุ

คําอธิบาย: ส่งกลับการอ้างอิงไปยังฟอร์มหรือรายการบนฟอร์ม เช่น ตารางที่สามารถแก้ไขได้ โดยขึ้นอยู่กับตําแหน่งที่ถูกเรียกเมธอด วิธีนี้ช่วยให้คุณสามารถสร้างตัวจัดการเหตุการณ์ทั่วไปที่สามารถดําเนินการบนฟอร์มหรือรายการบนฟอร์มขึ้นอยู่กับตําแหน่งที่เรียกใช้

ตัวอย่าง

โค้ดตัวอย่างต่อไปนี้สาธิตวิธีการที่คุณสามารถสร้างเมธอด ที่ตั้งค่าการแจ้งเตือนในคอลัมน์ของฟอร์มหรือเซลล์เส้นตารางที่สามารถแก้ไขได้ โดยขึ้นอยู่กับตําแหน่งที่คุณลงทะเบียนสคริปต์ (เหตุการณ์ Column OnChange หรือเหตุการณ์ OnChange บน ตารางที่สามารถแก้ไขได้):

function commonEventHandler(executionContext) {
    var formContext = executionContext.getFormContext();    
    var telephoneAttr = formContext.data.entity.attributes.get('telephone1');
    var isNumberWithCountryCode = telephoneAttr.getValue().substring(0,1) === '+';

    // telephoneField will be a form control if invoked from a form OnChange event;
    // telephoneField will be a editable grid GridCell object if invoked from editable grid OnChange event.
    var telephoneField = telephoneAttr.controls.get(0);

    if (!isNumberWithCountryCode) {
        telephoneField.setNotification('Please include the country code beginning with '+'.', 'countryCodeNotification');
    }
    else {
        telephoneField.clearNotification('countryCodeNotification');
    }
}

บริบทการดําเนินการ
บริบทของฟอร์ม