{"id":4735,"date":"2023-03-14T17:41:26","date_gmt":"2023-03-14T16:41:26","guid":{"rendered":"https:\/\/www.open-user-map.com\/?post_type=ht_kb&#038;p=4735"},"modified":"2024-11-11T22:46:39","modified_gmt":"2024-11-11T21:46:39","slug":"conditional-fields","status":"publish","type":"ht_kb","link":"https:\/\/www.open-user-map.com\/es\/knowledge-base\/conditional-fields\/","title":{"rendered":"Campos condicionales"},"content":{"rendered":"<p>Mostrar u ocultar un Campo personalizado en funci\u00f3n del valor seleccionado de otro Campo.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Esta es la funci\u00f3n Javascript que puedes utilizar para hacer esto posible:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\" data-no-translation=\"\" data-no-auto-translation=\"\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#333545;color:#ebebe6\">JavaScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"\/*** OUM: Conditional Field** sourceField Element that defines the condition* targetField Element to show or hide* condShow Array of values that lead to show* condHide Array of values that lead to hide*\/oumConditionalField(sourceField, targetField, condShow, condHide);\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code data-no-translation=\"\" data-no-auto-translation=\"\"><span class=\"line\"><span style=\"color: #7B7F8B\">\/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">* OUM: Conditional Field<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">*<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">* sourceField Element that defines the condition<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">* targetField Element to show or hide<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">* condShow Array of values that lead to show<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">* condHide Array of values that lead to hide<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">*\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #62E884\">oumConditionalField<\/span><span style=\"color: #F6F6F4\">(sourceField, targetField, condShow, condHide);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<div style=\"height:54px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>He aqu\u00ed un ejemplo:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.75rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\" data-no-translation=\"\" data-no-auto-translation=\"\"><span style=\"display:flex;align-items:center;padding:10px 0px 10px 16px;margin-bottom:-2px;width:100%;text-align:left;background-color:#333545;color:#ebebe6\">JavaScript<\/span><span role=\"button\" tabindex=\"0\" data-code=\"oumConditionalField('[name=&quot;oum_marker_icon[]&quot;]', '[name=&quot;oum_location_custom_fields[1645650268221]&quot;]', ['1', '2'], ['3', '']);\" style=\"color:#f6f6f4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code data-no-translation=\"\" data-no-auto-translation=\"\"><span class=\"line\"><span style=\"color: #62E884\">oumConditionalField<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #E7EE98\">&#91;name=&quot;oum_marker_icon&#91;&#93;&quot;&#93;<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #E7EE98\">&#91;name=&quot;oum_location_custom_fields&#91;1645650268221&#93;&quot;&#93;<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #F6F6F4\">, &#91;<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #E7EE98\">1<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #E7EE98\">2<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #F6F6F4\">&#93;, &#91;<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #E7EE98\">3<\/span><span style=\"color: #DEE492\">&#39;<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #DEE492\">&#39;&#39;<\/span><span style=\"color: #F6F6F4\">&#93;);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>El campo personalizado con el atributo <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">name=\u201doum_location_custom_fields[1645650268221]\u201d<\/mark> s\u00f3lo aparecer\u00e1 si el valor del campo con el atributo <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">name=\"oum_marker_icon[]\"<\/mark> tiene valor <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">1<\/mark> o <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">2<\/mark>. En caso de <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">3<\/mark> o un <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">vac\u00edo<\/mark> se ocultar\u00e1.<\/p>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Mostrar u ocultar un Campo Personalizado basado en el valor seleccionado de otro Campo. Esta es la funci\u00f3n Javascript que puede utilizar para hacer esto posible: He aqu\u00ed un ejemplo: El campo personalizado con el atributo name=\"oum_location_custom_fields[1645650268221]\" s\u00f3lo se mostrar\u00e1 si el valor del campo con el atributo name=\"oum_marker_icon[]\" tiene valor 1 o ... <a href=\"https:\/\/www.open-user-map.com\/es\/knowledge-base\/conditional-fields\/\">Contin\u00faa en<\/a><\/p>","protected":false},"author":50,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[25],"ht-kb-tag":[87,85,58,88,86],"class_list":["post-4735","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-customization","ht_kb_tag-conditional","ht_kb_tag-conditions","ht_kb_tag-custom","ht_kb_tag-fields","ht_kb_tag-form"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Conditional fields - Open User Map<\/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.open-user-map.com\/es\/knowledge-base\/conditional-fields\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Conditional fields - Open User Map\" \/>\n<meta property=\"og:description\" content=\"Show or hide a Custom Field based on the selected value of another Field. This is the Javascript function you can use to make this possible: Here is an example: The custom field with the attribute name=&#8221;oum_location_custom_fields[1645650268221]&#8221; will only show up if the value of the field with the attribute name=&#8221;oum_marker_icon[]&#8221; has value 1 or &hellip; Continued\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.open-user-map.com\/es\/knowledge-base\/conditional-fields\/\" \/>\n<meta property=\"og:site_name\" content=\"Open User Map\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-11T21:46:39+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minuto\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/\"},\"author\":{\"name\":\"Daniel Sch\u00f6nherr\",\"@id\":\"https:\/\/www.open-user-map.com\/#\/schema\/person\/d9c8cbe470ae2702b6de61e0f73a7402\"},\"headline\":\"Conditional fields\",\"datePublished\":\"2023-03-14T16:41:26+00:00\",\"dateModified\":\"2024-11-11T21:46:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/\"},\"wordCount\":76,\"publisher\":{\"@id\":\"https:\/\/www.open-user-map.com\/#organization\"},\"inLanguage\":\"es\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/\",\"url\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/\",\"name\":\"Conditional fields - Open User Map\",\"isPartOf\":{\"@id\":\"https:\/\/www.open-user-map.com\/#website\"},\"datePublished\":\"2023-03-14T16:41:26+00:00\",\"dateModified\":\"2024-11-11T21:46:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.open-user-map.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Conditional fields\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.open-user-map.com\/#website\",\"url\":\"https:\/\/www.open-user-map.com\/\",\"name\":\"Open User Map\",\"description\":\"WordPress Map Plugin\",\"publisher\":{\"@id\":\"https:\/\/www.open-user-map.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.open-user-map.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.open-user-map.com\/#organization\",\"name\":\"Open User Map\",\"url\":\"https:\/\/www.open-user-map.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/www.open-user-map.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.open-user-map.com\/wp-content\/uploads\/2023\/09\/icon-256x256-1.png\",\"contentUrl\":\"https:\/\/www.open-user-map.com\/wp-content\/uploads\/2023\/09\/icon-256x256-1.png\",\"width\":256,\"height\":256,\"caption\":\"Open User Map\"},\"image\":{\"@id\":\"https:\/\/www.open-user-map.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.open-user-map.com\/#\/schema\/person\/d9c8cbe470ae2702b6de61e0f73a7402\",\"name\":\"Daniel Sch\u00f6nherr\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Campos condicionales - Open User Map","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.open-user-map.com\/es\/knowledge-base\/conditional-fields\/","og_locale":"es_ES","og_type":"article","og_title":"Conditional fields - Open User Map","og_description":"Show or hide a Custom Field based on the selected value of another Field. This is the Javascript function you can use to make this possible: Here is an example: The custom field with the attribute name=&#8221;oum_location_custom_fields[1645650268221]&#8221; will only show up if the value of the field with the attribute name=&#8221;oum_marker_icon[]&#8221; has value 1 or &hellip; Continued","og_url":"https:\/\/www.open-user-map.com\/es\/knowledge-base\/conditional-fields\/","og_site_name":"Open User Map","article_modified_time":"2024-11-11T21:46:39+00:00","twitter_card":"summary_large_image","twitter_misc":{"Tiempo de lectura":"1 minuto"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#article","isPartOf":{"@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/"},"author":{"name":"Daniel Sch\u00f6nherr","@id":"https:\/\/www.open-user-map.com\/#\/schema\/person\/d9c8cbe470ae2702b6de61e0f73a7402"},"headline":"Conditional fields","datePublished":"2023-03-14T16:41:26+00:00","dateModified":"2024-11-11T21:46:39+00:00","mainEntityOfPage":{"@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/"},"wordCount":76,"publisher":{"@id":"https:\/\/www.open-user-map.com\/#organization"},"inLanguage":"es"},{"@type":"WebPage","@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/","url":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/","name":"Campos condicionales - Open User Map","isPartOf":{"@id":"https:\/\/www.open-user-map.com\/#website"},"datePublished":"2023-03-14T16:41:26+00:00","dateModified":"2024-11-11T21:46:39+00:00","breadcrumb":{"@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.open-user-map.com\/knowledge-base\/conditional-fields\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.open-user-map.com\/"},{"@type":"ListItem","position":2,"name":"Conditional fields"}]},{"@type":"WebSite","@id":"https:\/\/www.open-user-map.com\/#website","url":"https:\/\/www.open-user-map.com\/","name":"Open User Map","description":"Plugin de mapas de WordPress","publisher":{"@id":"https:\/\/www.open-user-map.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.open-user-map.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"es"},{"@type":"Organization","@id":"https:\/\/www.open-user-map.com\/#organization","name":"Open User Map","url":"https:\/\/www.open-user-map.com\/","logo":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/www.open-user-map.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.open-user-map.com\/wp-content\/uploads\/2023\/09\/icon-256x256-1.png","contentUrl":"https:\/\/www.open-user-map.com\/wp-content\/uploads\/2023\/09\/icon-256x256-1.png","width":256,"height":256,"caption":"Open User Map"},"image":{"@id":"https:\/\/www.open-user-map.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.open-user-map.com\/#\/schema\/person\/d9c8cbe470ae2702b6de61e0f73a7402","name":"Daniel Sch\u00f6nherr"}]}},"_links":{"self":[{"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/ht-kb\/4735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/comments?post=4735"}],"version-history":[{"count":0,"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/ht-kb\/4735\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/media?parent=4735"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/ht-kb-category?post=4735"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.open-user-map.com\/es\/wp-json\/wp\/v2\/ht-kb-tag?post=4735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}