{"pc":{"type":"Grid","model":{"stacked":"md","frame":{"horizontal":null,"vertical":null,"radius":null},"border":{"width":null,"color":null},"rows":[{"cells":[{"component":{"type":"Text","model":{"_internalName":"Text1","text":"<h1>Purchase agreement form</h1>"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"number","title":{"text":"Contract Number","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":7}},{"component":{"type":"Date","model":{"_internalName":"executionDate","title":{"text":"Date","visible":true},"orientation":"Vertical","required":false,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"startDate":{"mode":"Fixed"},"endDate":{"mode":"Fixed"}}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":5}}]},{"cells":[{"component":{"type":"Text","model":{"_internalName":"Text2","text":"<h3>Seller information</h3>"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"companyName","title":{"text":"Seller company name","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"companyAddress","title":{"text":"Seller address","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"companyEmail","title":{"text":"Seller email","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cHint":"username@domain.com","cFont":{"style":"Normal","weight":"Normal"},"type":"E-mail","pattern":"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$","error":"This field must contain a valid e-mail address."}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"companyPhone","title":{"text":"Seller phone","visible":true},"orientation":"Vertical","required":false,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cHint":"123-456-7890","cFont":{"style":"Normal","weight":"Normal"},"type":"Phone","pattern":"^(\\+\\d{1,2}\\s)?\\(?\\d{3}\\)?[\\s.-]\\d{3}[\\s.-]\\d{4}$","error":"This field must contain a valid phone number."}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"Text","model":{"_internalName":"Text3","text":"<h3>Buyer information</h3>"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"buyerName","title":{"text":"Buyer company name","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"buyerEmail","title":{"text":"Buyer email","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cHint":"username@domain.com","cFont":{"style":"Normal","weight":"Normal"},"type":"E-mail","pattern":"^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$","error":"This field must contain a valid e-mail address."}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"buyerAddress","title":{"text":"Buyer address","visible":true},"orientation":"Vertical","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"DataTable","model":{"_internalName":"products","title":{"text":"products","visible":false},"required":false,"font":{"style":"Normal","weight":"Semibold"},"newLine":"Bottom","delete":"Last","columns":[{"_internalName":"name","title":"Products","required":true,"type":"String","aggregates":[]},{"_internalName":"quantity","title":"Quantity","required":true,"type":"Number","aggregates":[],"min":0,"precision":2,"percents":false,"spinButtons":false},{"_internalName":"price","title":"Unit Price","required":true,"type":"Number","aggregates":[],"min":0,"precision":2,"percents":false,"spinButtons":false},{"_internalName":"cost","title":"Total cost","required":true,"type":"Number","aggregates":[],"min":0,"precision":2,"percents":false,"spinButtons":false}]}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":12}}]},{"cells":[{"component":{"type":"SingleLineText","model":{"_internalName":"OrderTotal","title":{"text":"Total ($)","visible":true},"orientation":"Horizontal","required":true,"font":{"style":"Normal","weight":"Semibold"},"wrap":true,"cFont":{"style":"Normal","weight":"Normal"},"type":"Anything"}},"alignment":{"horizontal":"Justify","vertical":"Top"},"columns":{"width":4,"offset":8}}]},{"cells":[{"component":{"type":"Submit","model":{"_internalName":"Submit1","text":"Create contract","savingText":"Submitting...","type":"Primary","click":"return fd.save();"}},"alignment":{"horizontal":"Left","vertical":"Top"},"columns":{"width":6}}]}]}},"tablet":null,"phone":null,"js":"//once the form is rendered\r\nfd.rendered(function() {\r\n    //Disable Order Total field\r\n    fd.field('OrderTotal').disabled = true;\r\n    //Make Total column noneditable\r\n    fd.control('products').columns[3].editable =\r\n        function(){return false};\r\n    fd.control('products').$on('change', function(value) {\r\n        //variable to count Order Total\r\n        var orderTotal = 0;\r\n        //if there are records in the table\r\n        var isTableModified = false;\r\n        if(value){\r\n            //go through each one by one\r\n            for (var i = 0; i < value.length; i++){\r\n                //if this record has Amount and Price\r\n                if(value[i].quantity && value[i].price){\r\n                    //set Total to their product\r\n                    var cost = value[i].quantity * value[i].price;\r\n                    if (value[i].cost != cost) {\r\n                        value[i].cost = cost;\r\n                        isTableModified = true;\r\n                    }\r\n                //add Total to the Order Total\r\n                orderTotal += parseInt(value[i].cost);\r\n                }\r\n            }\r\n        }\r\n        //here we make our change to the table\r\n        if (isTableModified) {\r\n            fd.control('products').value = value;\r\n        }\r\n        //we set Order Total field to sum of Totals\r\n        fd.field('OrderTotal').value = orderTotal;\r\n    });\r\n});\r\n\r\n/*****************************************************************************\r\nThe JavaScript code from this section will be executed while loading\r\nthe current form.\r\n\r\nThe following predefined variables can be utilized in the code:\r\n\r\nfd  - instance of the current form\r\n$   - jQuery object\r\n\r\n==============================================================================\r\n\r\nfd.rendered(function () {\r\n    // This code is executed once the form is rendered\r\n\r\n    // Hide State field for all values of Country field except 'USA'\r\n    function updateStateVisibility() {\r\n        var stateContainer = $(fd.field('State').$el).closest('.form-group');\r\n        if (fd.field('Country').value === 'USA') {\r\n            stateContainer.show();\r\n        } else {\r\n            stateContainer.hide();\r\n        }\r\n    }\r\n\r\n    // Set initial State visibility\r\n    updateStateVisibility();\r\n\r\n    // Update State visibility after changing Country\r\n    fd.field('Country').$on('change', updateStateVisibility)\r\n});\r\n\r\nfd.beforeSave(function () {\r\n    // This code is exeuted before saving the form and\r\n    // may return Promise. The saving does not proceed until\r\n    // the Promise is resolved. If the Promise is rejected,\r\n    // the saving interrupts. This is the appropriate place\r\n    // for adding custom validation.\r\n\r\n    // Prevent saving if Start Date is greater than End Date\r\n    if (fd.field('StartDate').value > fd.field('EndDate').value) {\r\n        throw Error('Start Date must not be greater than End Date.');\r\n    }\r\n});\r\n\r\nfd.saved(function (result) {\r\n    // This code is executed after saving the form\r\n\r\n    // Forwarding users to specific URL\r\n    window.location = '--- Some URL ---';\r\n});\r\n\r\n*****************************************************************************/\r\n","css":null,"notifySubscribers":true,"version":"1.0.2","theme":{"themeId":"default","primary":"#008EFF","bodyText":"#373A3C","bodyBackground":"#FFFFFF","fontSize":15,"fontWeight":400,"borderThickness":1,"borderRadius":2,"shadow":true,"isDark":false,"fontFamily":null,"fontType":0},"timezone":"Europe/Kirov","culture":"en","userLanguage":null,"userCulture":null,"thankYouMessage":null,"redirectURL":null,"hideAfterSubmission":true,"submissionTimeout":0,"authentication":0,"singleSubmissionPerUser":false,"allowEditingSubmission":false,"restrictAccess":false,"azureADTenant":null,"azureADObjects":[],"entraExternalIdProperties":null,"azureB2CProperties":null,"connection":null}