Jump to content

Archived

This topic is now archived and is closed to further replies.

244863

CakePHP unlockedFields error

Recommended Posts

Here is the code for my view:

<div class="column span-24">
	<div class="box">
		<?php
			echo $this->html->tag('h2', $title_for_layout);
			echo $this->form->create('DocumentationDocument', array('action' => 'add', 'type' => 'file'));
			
			echo $this->form->inputs(array(
				'File' => array(
					'type' => 'file',
					'label' => __('Local File', true),
					'required' => true
				),
				'site_id' => array(
					'type' => 'hidden'
				),
				'site_name' => array(
					'class' => 'site_name span-8',
					'type' => 'text',
					'required' => true,
					'between' => $this->html->tag(
						'div',
						$this->html->para('notice', __('Begin typing the site name and choose from the resultant list.', true)),
						array('class' => 'field-description')
					)
				),
				'documentation_category_id' => array(
					'empty' => '...',
					'class' => 'span-8',
					'required' => true
				),
				'asset_category_id' => array(
					'empty' => '...',
					'class' => 'span-8',
					'required' => true
				),
				'date_produced' => array('type' => 'date')
			));
			
			echo $this->html->para('notice', sprintf("Maximum file size: $size_limit"));
			
			echo $this->element('standard-form-buttons');
		?>
	</div>
</div>
<?php
	echo $this->element('sites', array(), array('cache' => true));
	
	echo $this->html->scriptBlock('
		$(function() {
			$(".site_name").autocomplete(sites, {
				dataType: "json",
				matchContains: true,
				mustMatch: true,
				parse: function(data) {
					return $.map(data, function(row) {
						return {
							data: row,
							value: row.display_name,
							result: row.display_name
						}
					});
				},
				formatItem: function(item) {
					return item.display_name;
				},
				formatResult: function(item) {
					return item.display_name;
				}
			}).result(function(event, data, formatted) {
				if (data && data.id) {
					allSites = $(".site", $("#sites"));
					index = allSites.index($(this).closest(".site"));
					$("#DocumentationDocumentSiteId").val(data.id);
					$(this).siblings(".error-message").hide(100).parent().removeClass("error");
				}
			});
		});
	', array('inline' => false));

	$this->Form->unlockField('DocumentationDocument.site_id');
	echo $this->form->end();
?>

If I remove the following line of JS the page posts fine:

 

$("#DocumentationDocumentSiteId").val(data.id);

 

I am pretty sure I have the unlockedField line correct as it works on other pages.

 

Any ideas as to why it won't post?

 

Thanks,

Share this post


Link to post
Share on other sites

Hi,

 

Tried this in my app controller's before filter:

 

        $this->Security->unlockFields = array('DocumentationDocument.site_id');

still does not work, unless I uncomment that line of code???

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.