{"id":71,"date":"2019-08-24T09:32:58","date_gmt":"2019-08-24T09:32:58","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=71"},"modified":"2020-09-08T14:55:48","modified_gmt":"2020-09-08T09:25:48","slug":"mark-a-field-required-conditionally","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/","title":{"rendered":"Mark a field Required conditionally"},"content":{"rendered":"\n<p>We have done the code for &lt;desired_module> module. Change it as per your requirement. We  will mark &#8220;Description&#8221; field required if status is Publish <\/p>\n\n\n\n<p> Steps are as below,<\/p>\n\n\n\n<p><strong>1.<\/strong> <strong>Add a reference to the JavaScript file which will be needed for event binding.<\/strong><\/p>\n\n\n\n<p><strong>Path:<\/strong>&nbsp;custom\/modules\/&lt;desired_module&gt;\/metadata\/editviewdefs.php<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$viewdefs['&lt;desired_module>']['EditView']['templateMeta']['includes'] =\n    array (\n        array (\n        'file' => 'custom\/modules\/&lt;desired_module>\/js\/editview.js',\n        ),\n    );\n?><\/code><\/pre>\n\n\n\n<p><strong>2.<\/strong>  <strong>Add the JavaScript file you want to include into the location you referenced above(custom\/modules\/&lt;desired_module&gt;\/js\/editview.js). <\/strong><\/p>\n\n\n\n<p><strong>3.  Write following code in  editview.js file. <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/\/ Change status to the field of your module\n$('#status').change(function() {\n\tmakerequired(); \/\/ onchange call function to mark the field required\n});\nfunction makerequired()\n{\nvar status = $('#status').val(); \/\/ get current value of the field \n if(status == 'Publish'){ \/\/ check if it matches the condition: if true,\n\t\taddToValidate('EditView','description','varchar',true,'Description');    \/\/ mark Description field required\n\t\t$('#description_label').html('Description: &lt;font color=\"red\">*&lt;\/font>'); \/\/ with red * sign next to label\n\t}\n\telse{\n\t\tremoveFromValidate('EditView','description');                        \/\/ else remove the validtion applied\n\t\t$('#description_label').html('Description: '); \/\/ and give the normal label back \n\t}\n}\nmakerequired(); \/\/Call at onload while editing a Published blog record<\/code><\/pre>\n\n\n\n<p><strong>4.  Quick Repair, then hard refresh your browser. All Done ! <\/strong><\/p>\n\n\n\n<p><strong>5. Done! Refresh the page and start testing. <\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong><\/p><cite> 1. Read the comments in code carefully and replace the variables as asked. <br> 2.  Here, &lt;desired_module&gt; means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc. <br> 3. You may find the field names and its labels in Admin &gt; Studio &gt; &lt;Your_module&gt; &gt; Fields &gt; &lt;Choose correct field&gt; &gt; Take&nbsp;<strong>Field Name<\/strong>&nbsp;and&nbsp;<strong>System Label<\/strong>. <\/cite><\/blockquote>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"612\" height=\"347\" src=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg\" alt=\"\" class=\"wp-image-74\"\/><figcaption>Before Customization<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"367\" src=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-2.jpg\" alt=\"\" class=\"wp-image-75\"\/><figcaption> After Customization <\/figcaption><\/figure><\/div>\n\n\n\n<p>\n\nHope you find this blog post helpful.<\/p>\n\n\n\n<p>Feel free to add comments and queries, that helps us to improve the quality of posts.<\/p>\n\n\n\n<p>You can contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:contact@urdhva-tech.com\" target=\"_blank\">info@techcrm.in<\/a><\/p>\n\n\n\n<p>Thank you.\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have done the code for &lt;desired_module> module. Change it as per your requirement. We will mark &#8220;Description&#8221; field required if status is Publish Steps are as below, 1. Add a reference to the JavaScript file which will be needed for event binding. Path:&nbsp;custom\/modules\/&lt;desired_module&gt;\/metadata\/editviewdefs.php 2. Add the JavaScript file you want to include into the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[16,12,13],"class_list":["post-71","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-editview","tag-sugarcrm","tag-suitecrm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Mark a field Required conditionally - TechCRM<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mark a field Required conditionally - TechCRM\" \/>\n<meta property=\"og:description\" content=\"We have done the code for &lt;desired_module&gt; module. Change it as per your requirement. We will mark &#8220;Description&#8221; field required if status is Publish Steps are as below, 1. Add a reference to the JavaScript file which will be needed for event binding. Path:&nbsp;custom\/modules\/&lt;desired_module&gt;\/metadata\/editviewdefs.php 2. Add the JavaScript file you want to include into the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-24T09:32:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:25:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg\" \/>\n<meta name=\"author\" content=\"Navin Rakhonde\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Navin Rakhonde\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/\",\"name\":\"Mark a field Required conditionally - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg\",\"datePublished\":\"2019-08-24T09:32:58+00:00\",\"dateModified\":\"2020-09-08T09:25:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg\",\"contentUrl\":\"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SugarCRM\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Mark a field Required conditionally\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/\",\"name\":\"TechCRM\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\",\"name\":\"Navin Rakhonde\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"caption\":\"Navin Rakhonde\"},\"sameAs\":[\"https:\/\/www.techcrm.in\/\"],\"url\":\"https:\/\/www.techcrm.in\/blogs\/author\/navin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mark a field Required conditionally - TechCRM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/","og_locale":"en_US","og_type":"article","og_title":"Mark a field Required conditionally - TechCRM","og_description":"We have done the code for &lt;desired_module> module. Change it as per your requirement. We will mark &#8220;Description&#8221; field required if status is Publish Steps are as below, 1. Add a reference to the JavaScript file which will be needed for event binding. Path:&nbsp;custom\/modules\/&lt;desired_module&gt;\/metadata\/editviewdefs.php 2. Add the JavaScript file you want to include into the [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/","og_site_name":"TechCRM","article_published_time":"2019-08-24T09:32:58+00:00","article_modified_time":"2020-09-08T09:25:48+00:00","og_image":[{"url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg"}],"author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/","url":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/","name":"Mark a field Required conditionally - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage"},"image":{"@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage"},"thumbnailUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg","datePublished":"2019-08-24T09:32:58+00:00","dateModified":"2020-09-08T09:25:48+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#primaryimage","url":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg","contentUrl":"https:\/\/www.techcrm.in\/blogs\/wp-content\/uploads\/2019\/08\/blog-21-screen-1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/mark-a-field-required-conditionally\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techcrm.in\/blogs\/"},{"@type":"ListItem","position":2,"name":"SugarCRM","item":"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/"},{"@type":"ListItem","position":3,"name":"Mark a field Required conditionally"}]},{"@type":"WebSite","@id":"https:\/\/www.techcrm.in\/blogs\/#website","url":"https:\/\/www.techcrm.in\/blogs\/","name":"TechCRM","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc","name":"Navin Rakhonde","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","caption":"Navin Rakhonde"},"sameAs":["https:\/\/www.techcrm.in\/"],"url":"https:\/\/www.techcrm.in\/blogs\/author\/navin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":6,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/71\/revisions\/220"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}