From c971a9923b02f009175365346a0d5b5faa0912bb Mon Sep 17 00:00:00 2001 From: Tyler Frankenstein Date: Wed, 4 Sep 2013 01:06:21 -0400 Subject: [PATCH] Added drupalgap_form_element_access() and changed _drupalgap_form_render_elements() to check the 'access' property on the form's elements and buttons before rendering them. --- includes/form.inc.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/includes/form.inc.js b/includes/form.inc.js index 2a4304d0..669d332d 100644 --- a/includes/form.inc.js +++ b/includes/form.inc.js @@ -24,6 +24,19 @@ function drupalgap_form_defaults(form_id) { return form; } +/** + * Given a form element, this will return true if access to the element is + * permitted, false otherwise. + */ +function drupalgap_form_element_access(element) { + try { + var access = true; + if (element.access == false) { access = false; } + return access; + } + catch (error) { drupalgap_error(); } +} + /** * Given a form element name and the form_id, this generates an html id * attribute value to be used in the DOM. @@ -261,15 +274,24 @@ function _drupalgap_form_render_elements(form) { try { var content = ''; // For each form element, if the element objects name property isn't set, - // set it, then render the element. + // set it, then render the element if access is permitted. $.each(form.elements, function(name, element){ if (!element.name) { element.name = name; } - content += _drupalgap_form_render_element(form, element); + if (drupalgap_form_element_access(element)) { + content += _drupalgap_form_render_element(form, element); + } }); - // Add any form buttons to the form elements html. + // Add any form buttons to the form elements html, if access to the button + // is permitted. if (form.buttons && form.buttons.length != 0) { $.each(form.buttons, function(name, button){ - content += ''; + if (drupalgap_form_element_access(button)) { + var attributes = { + type:'button', + id:drupalgap_form_get_element_id(name, form.id) + }; + content += ''; + } }); } return content;