AngularJS and ns-select without ng-option - angularjs

in my page I load the content of a div via "ng-include src". In this content I have a <select> item:
<select name="relationship" ng-model="userEdit.relationship">
<?php
$tree = taxonomy_get_tree(5);
foreach ($tree as $row) {
echo "<option value=".$row->tid.">".$row->name."</option>\n";
}
?>
</select>
In my "controller" function I can not to create this tree into an array to pass to "ng-options" because I have no access to source tree via web. I can only read the full HTML form. I can change the source of the form (if I need to inject something for example) but I can not get the original tree in my controller.
However, the HTML is ok, but when I choose my "relationship" and send the form (ng-click="myfunction()") to my controller function i can see that there is no "relationship" in "userEdit" object.
Where is my error ?
Thanks.

You are missing quotes
echo "<option value='".$row->tid."'>".$row->name."</option>\n";

Related

How to pass entire objects from Controller to Twig in Symfony 3?

I'm triyng to pass an object to Twig.
The object is the representation of an Entity, obtained via the
getDoctrine()->getManager()->getRepository(/*repoName*/)->find(id);
This actually works but how can I display all of its values in a html table in Twig?
I tried serialization but with no success, maybe I am missing something, please help.
Thanks in advance!
UPDATE:
What I actually want to achieve is to iterate to that object WITHOUT knowing its keys, a sort of
foreach (field in object) print key, value
$object = $em->getDoctrine()->getManager()->getRepository(/*repoName*/)->find(id);
You need pass this variable to the template by :
return $this->render('Anypath/your_template.html.twig', ['obj'=>$object]);
than from the twig :
{{obj.id}} or {{obj.name}}
depends on your fields inside object.
In your controller:
return $this->render('path/template.html.twig', ['entity'=>$entity]);
and in your template (replace your_attribute_name by any attribute of your entity):
{{ entity.your_attribute_name }}
Once you send your object to you twig template
return $this->render("AppBundle:Records:template.html.twig", [
"$object" => $object
]);
You can just do:
{{ object.field }}
That correspond to doing $object->getField() in PHP
Then just build your list manually in your twig
You you wanna loop through your object have a look at thise subject
Twig iterate over object properties
{% for key, value in my_object|cast_to_array %}
This might help

Delete div generated by CakePHP Form create

CakePHP Code
<?php echo $this->Form->create('KPI');?>
HTML Output
<form accept-charset="utf-8" method="post" id="..." action="...">
<div style="display:none;">
<input type="hidden" value="POST" name="_method">
</div>
I want to delete auto generated div which display in html output. How can delete that div which generated by cakephp form create?
As already mentioned in the comments, you should not remove that markup, besides that would only be possible by completely overwriting FormHelper::create(), see
https://github.com/.../cakephp/blob/2.5.6/lib/Cake/View/Helper/FormHelper.php#L426-L432
https://github.com/.../cakephp/blob/2.5.6/lib/Cake/View/Helper/FormHelper.php#L462-L464
Also note that there might be an additional hidden block at the end of the form, see FormHelper::secure().
The only simpler way to remove the wrapper, would be to remove the hidden wrappers altogether, that would for example be possible by using a custom config for HtmlHelper where the hiddenblock tag is modified so that it doesn't contain the wrapper, however that's not a good idea - don't do it!
The problem here is that you can't just remove this specific wrapping div element, the hidden input and the div go hand in hand. And the input ensures that CakePHP is able to figure the proper request method (POST, PUT, DELETE).
So instead simply make your jQuery selector more specific, do not just select div elements, instead make sure that your elements have a proper class set, and then select them by that class.
<?php echo $this->Form->create('Kpi', array(
'inputDefaults'=>array('div'=>'false', 'label'=>false)));
?>

angular.js: how can you load a remote html file, and populate one of it's elements with model's data?

I have global ng-app declared on the HTML tag level. There's a static element, that get's handled by specific ng-controller. Now, at some point of page usage flow, a widget gets loaded into the DOM. Widget lands outside the ng-controller element. Question: how can I populate that widget with data from angular's model and keep it in sync?
Using this simple code doesn't work:
<select ng-model="files" ng-options="f.name for f in files">
<option value="">Select File</option>
</select>
Worth saying, that the widget is only a part of large amount of content (i.e. page) that gets loaded dynamically, which is why I'm trying to avoid declaring a controller for each of 'pages', as it looks to be an overkill.

Custom Input HTML with CakePHP's FormHelper

I'm trying to use CakePHP's form helper to generate some input elements.
The HTML I am trying to generate is:
<div class="formRow">
<label>LabelText:</label>
<div class="formRight">
<input name="data[User][email_address]" type="text" value="">
</div>
<div class="clear"></div>
</div>
Ive had a look through the Cake documentation (Using 2.1) and I can't find enough information on how to do this.
It looks like I need to use the format option on the input method, but can't figure out how to get it right. Especially concerned about the div surrounding the input field with a class name on it..
E.g. Ive tried something like this:
echo $this->Form->input('email_address', array(
"input" => array('attributes' => array('wrap' => 'div','class' => 'formRight'))));
But this doesnt change any of the markup and just throws this error:
Notice (8): Array to string conversion [CORE\Cake\View\Helper.php, line 459]
So my question is how can I get this form helper to create that markup?
Any help much appreciated
You're over-thinking it. (No worries, we all do). Just remember, CakePHP is all about making things easier for you (among other things) - if you're struggling with trying to force Cake to do something for you, just remember, you can fall back to the basics - it's just PHP/HTML after-all.
<div class="formRow">
<label>LabelText:</label>
<div class="formRight">
<?php echo $this->Form->input('email_address', array(
'div'=>false, 'label'=>false)); ?>
</div>
<div class="clear"></div>
</div>
You should use the Form helper for your forms when possible, but you don't have to use all of it's presets like surrounding divs & labels. In the case above, just tell it you don't want the div, and wrap it with a div yourself.
If you don't want <div>s or <label>s around any inputs, you can also set the form's inputDefaults:
$this->Form->create('Whatever', array(
'inputDefaults' => array('label'=>false, 'div'=>false)
));
If you have a lot of fields, you can use Jquery.
php:
echo $this->Form->input('email_address', array('class' => 'formRow'));
Jquery:
$(".formRow").each(function() {
$(this).wrapInner( "<div class='formRight'></div>");
$(this).find("label").prependTo(this);
$(this).append('<div class="clear"></div>');
});

How to pass an array as a hidden field?

I am implementing an auto complete box using the Ajax.autocompleter method of the scriptaculous.js framework.
This is the auto complete box and the div where the auto suggested entries are populated.
<?php echo $form->create('Share', array('url' => '/forms/share')); ?>
<label for="shareWith">Share Form with</label>
<input type="text" id="autocomplete" name="autocomplete_parameter"/>
<div id="autocomplete_choices" class="autocomplete"></div>
<input type="hidden" id="sharedUserId" name="sharedUserId"/>
<?php echo $form->end('Share');?>
This is the JQuery function to get the auto-suggested list and to get the id of the selected entry which is stored in the hidden field of the form.
new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
"http://localhost/FormBuilder/forms/autoComplete",
{
tokens: ',',
afterUpdateElement : getSelectedId
}
);
function getSelectedId(text, li) {
$("#sharedUserId").val(li.id);
}
Suppose if I select multiple entries,how to send those values?
Can I have an array as a hidden field, so that I can have an array of the selected elements and save that array as a hidden field?
Simply create a new hidden input field for every selected ID, and make sure that for each you have name="sharedUserId[]". This doesn't follow the CakePHP form element naming convention, but it will make sure that the POSTed value of sharedUserId is an array.
serialize with json and parse it in the server back. PHP 5.2 can parse json natively.
Not related to your question though..
http://docs.jquery.com/Plugins/Autocomplete
jQuery Auto complete you

Resources