Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Filter FK by created_by 01 Dec 2017 10:30 #15465

  • MorganL
  • MorganL's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
  • Posts: 438
  • Thank you received: 53
I want an FK field on a form to only list records created by the logged in user. This is working fine for filters, but seems to be missing from FK fields.

It is worth noting that this is one of my two remaining legacy projects (not ORM)

Here is what I have
	<?php
	// Associated Title
	$field = $fieldSet['jform_associated_title'];
	$field->jdomOptions = array(
		'groupBy' => array(
			'type' => 'type'
		),

		'created_by' => $this->item->created_by, /// THIS WAS ADDED BY ME
		'list' => $this->lists['fk']['associated_title']
	);
	?>
	<div class="control-group <?php echo 'field-' . $field->id . $field->responsive; ?>">
		<div class="control-label">
			<?php echo $field->label; ?>
		</div>

		<div class="controls">
			<?php echo $field->input; ?>
		</div>
	</div>
	<?php echo(MyComponentHelperHtmlValidator::loadValidator($field)); ?>

The cretaed by filter was added by me thinking it would work. but it doesnt. Is there an option I can use in the JDom options to filter the FK Select field (single choice) by the logged in users records like the filter dropdown does
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla

Please Log in or Create an account to join the conversation.

Filter FK by created_by 01 Dec 2017 19:08 #15468

When I encountered this, I solved it by overriding the $this->lists or use 'list' => $associated_title_model->getItems();
$associated_title_model would be a model from what you need and then adding wheres and such: $model->addWhere('a.created_by='.(int)$user->id)

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.068 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started