I need to take all matches on first level depth
http://framework.zend.com/manual/2.0/en/modules/zend.dom.query.html
It shows me all matches that contain class accordion + all child matches
$dom = new Query($html);
$results = $dom->execute('.accordion');
I'm getting all 6 nodes with class .accordion
Html
<div class="accordion">
Test1
<div class="accordion">
Test2
<div class="accordion">
Test3
</div>
</div>
</div>
<div class="accordion">
Name
<div class="accordion">
Name2
<div class="accordion">
Name3
</div>
</div>
</div>
How Can I take only the first levels of DOM Objcets(Nodelist) without childs?
It should be
First object
<div class="accordion">
Name
<div class="accordion">
Name2
<div class="accordion">
Name3
</div>
</div>
</div>
Second object
<div class="accordion">
Name
<div class="accordion">
Name2
<div class="accordion">
Name3
</div>
</div>
</div>
Thanks!
Well I've tested some code
$html = '
<div class="container">
<div class="accordion">
Test1
<div class="accordion">
Test2
<div class="accordion">
Test3
</div>
</div>
</div>
<div class="accordion">
Name
<div class="accordion">
Name2
<div class="accordion">
Name3
</div>
</div>
</div>
</div>
';
$dom = new \Zend\Dom\Query($html);
// Will returns the first levels .accordion in .container ($results length is 2)
$results = $dom->queryXpath('//div[#class="container"]/div[#class="accordion"]');
echo '<pre>';
foreach($results as $result){
print_r($result);
}
exit;
echo :
DOMElement Object
(
[tagName] => div
[schemaTypeInfo] =>
[nodeName] => div
[nodeValue] =>
Test1
Test2
Test3
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] => (object value omitted)
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => div
[baseURI] =>
[textContent] =>
Test1
Test2
Test3
)
DOMElement Object
(
[tagName] => div
[schemaTypeInfo] =>
[nodeName] => div
[nodeValue] =>
Name
Name2
Name3
[nodeType] => 1
[parentNode] => (object value omitted)
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] => (object value omitted)
[nextSibling] => (object value omitted)
[attributes] => (object value omitted)
[ownerDocument] => (object value omitted)
[namespaceURI] =>
[prefix] =>
[localName] => div
[baseURI] =>
[textContent] =>
Name
Name2
Name3
)
Related
I'm new to laravel I was created form wizard for multiple choose question answer using foreach loop.
When I checked Array value by dd($request->toArray()); I'm getting each OPTION value in different Array see my result
array:12 [▼ // app/Http/Controllers/ExamPanel/ExampanelController.php:63
"student_name" => "Test"
"Question" => array:2 [▼
0 => "which sub mane is used for voucher entry in tally"
1 => "Which option is used to view stock items (or ) group summary"
]
"OPTION1" => array:1 [▼
0 => "Vouchers"
]
"OPTION2" => array:1 [▼
0 => "display"
]
]
See this all Question In 1 Are 0,1 and many, But Option Creating different array like OPTION1,OPTION2. this not work for storing data represented question answer.
i need Option Shod have all array value 0,1,2, Like This.
my form
<div class="nk-stepper-steps stepper-steps">
#foreach ($ExaminationsQuestion as $key => $ExaminationsQuestions)
#php
$id = 1+$key
#endphp
<div class="nk-stepper-step">
<div class="nk-stepper-step-head mb-4">
<h5 class="title">{{1+$key}}) {{$ExaminationsQuestions->Question }}? </h5>
<input type="hidden" value="{{$ExaminationsQuestions->Question}}" name="Question[]">
</div>
<div class="row g-4">
<div class="col-12">
<div class="form-group">
<div class="form-control-wrap">
<ul class="custom-control-group flex-column align-start">
#foreach ($ExaminationsQuestions->options->shuffle() as $key => $optionss)
<!--filtterd data from 1st foreach-->
<li>
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" name="OPTION{{$id}}[]" value="{{ $optionss->OPTION }}" id="{{ $optionss->OPTION }}{{$id}}" >
<label class="custom-control-label" for="{{ $optionss->OPTION }}{{$id}}"> {{ $optionss->OPTION }}</label>
</div>
</li>
#endforeach
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="file-folder-breadcrumbs-child-panel ng-hide" ng-show="isExpanded(root.full)">
<!-- ngRepeat: child in root.nodes -->
<div ng-repeat="child in root.nodes" class="ui-state-default filedrop file-folder-breadcrumbs-item-child ng-scope" ng-click="navigateToChild($event, child, root)">
<span class="ng-binding">TestFolder</span>
</div>
<!-- end ngRepeat: child in root.nodes -->
</div>
I am not able to get TestFolder by using:
const myDiv=element.all(by.repeater('item in currentPathNodes track by $index')).filter(item => item.element(by.className('ui-state-default btn btn-toolbar ng-scope'))).filter(item => item.element(by.className('file-folder-breadcrumbs-item-part name'))).filter(item => item.element(by.className('ng-binding')).getText().then(label => label === fileName));
console.log(myDiv);
return folderName;
please help
I want to use Checklist Field in laravel backpack, but it says that we have to need a relation with another table. But I would like to put the Options in my CrudController like select_from_array.
I have no idea how to custom this field.
I want to use checklist instead of select_from_array
Create a file at resources/views/vendor/backpack/crud/fields/checklist_direct.blade.php with the below content (checklist_direct can be any name you choose):
<!-- checklist with directly provided options -->
<!-- checklist_filtered -->
#php
$options = isset($field['options']) ? $field['options'] : [];
#endphp
<div #include('crud::inc.field_wrapper_attributes') >
<label>{!! $field['label'] !!}</label>
#include('crud::inc.field_translatable_icon')
<?php $entity_model = $crud->getModel(); ?>
<div class="row">
#foreach ($options as $option)
<div class="col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox"
name="{{ $field['name'] }}[]"
value="{{ $option }}"
#if( ( old( $field["name"] ) && in_array($option , old( $field["name"])) ) )
checked = "checked"
#endif > {!! $option !!}
</label>
</div>
</div>
#endforeach
</div>
{{-- HINT --}}
#if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
#endif
</div>
Then update your call to addField to in your controller would look something like:
$this->crud->addField([
'label' => 'Printers',
'type' => 'checklist_direct',
'name' => 'printer',
'attribute' => 'printer_name',
'options' => ['HP', 'Cannon', 'Dell'],
]);
NOTE: You might also consider using an enum column on your table and using the enum.blade.php field template or possibly making a custom enum field that uses checkboxes instead of a select box.
I needed to do some updates on the code. I create a file at resources/views/vendor/backpack/crud/fields/checklist_array.blade.php with the below content (checklist_array can be any name you choose):
I updated the code for the one below, One of the updates I did was, when editing it did not bring the selected values. Now you are bringing through script in javascript
<!-- checklist with directly provided options -->
<!-- checklist_filtered -->
#php
$options = isset($field['options']) ? $field['options'] : [];
// calculate the value of the hidden input
$field['value'] = old(square_brackets_to_dots($field['name'])) ?? ($field['value'] ?? ($field['default'] ?? []));
if (is_string($field['value'])) {
$field['value'] = json_decode($field['value']);
}
// define the init-function on the wrapper
$field['wrapper']['data-init-function'] = $field['wrapper']['data-init-function'] ?? 'bpFieldInitChecklist';
#endphp
#include('crud::fields.inc.wrapper_start')
<label>{!! $field['label'] !!}</label>
#include('crud::fields.inc.translatable_icon')
<input type="hidden" value='#json($field['value'])' name="{{ $field['name'] }}">
<div class="row">
#foreach ($options as $option)
<div class="col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox" name="{{ $field['name'] }}[]" value="{{ $option }}" #if( ( old( $field["name"] )
&& in_array($option , old( $field["name"])) ) ) checked="checked" #endif> {!! $option !!}
</label>
</div>
</div>
#endforeach
</div>
{{-- HINT --}}
#if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
#endif
#include('crud::fields.inc.wrapper_end')
{{-- ########################################## --}}
{{-- Extra CSS and JS for this particular field --}}
{{-- If a field type is shown multiple times on a form, the CSS and JS will only be loaded once --}}
#if ($crud->fieldTypeNotLoaded($field))
#php
$crud->markFieldTypeAsLoaded($field);
#endphp
{{-- FIELD JS - will be loaded in the after_scripts section --}}
#push('crud_fields_scripts')
<script>
function bpFieldInitChecklist(element) {
//console.log(element);
var hidden_input = element.find('input[type=hidden]');
var selected_options = JSON.parse(hidden_input.val() || '[]');
var checkboxes = element.find('input[type=checkbox]');
var container = element.find('.row');
// set the default checked/unchecked states on checklist options
checkboxes.each(function(key, option) {
var id = $(this).val();
if (selected_options.map(String).includes(id)) {
$(this).prop('checked', 'checked');
} else {
$(this).prop('checked', false);
}
});
// when a checkbox is clicked
// set the correct value on the hidden input
checkboxes.click(function() {
var newValue = [];
checkboxes.each(function() {
if ($(this).is(':checked')) {
var id = $(this).val();
newValue.push(id);
}
});
hidden_input.val(JSON.stringify(newValue));
});
}
</script>
#endpush
#endif
{{-- End of Extra CSS and JS --}}
{{-- ########################################## --}}
//form
$this->crud->addField([
'label' => 'Printers',
'type' => 'checklist_direct',
'name' => 'printer',
'attribute' => 'printer_name',
'options' => ['HP', 'Cannon', 'Dell'],
]);
//model
protected $casts = [
...
'printer' => 'array',
];
My issue is that I keep on getting an argument error when trying to add subsections to my interview form which is nested under sections.
The Interview_kit has many sections and sections have many sub_sections. The sections belong to the interview_kit and the subsections belong to the section.
I would like to create all of this in the same form but am haveing no luck.
Is it possible to do this in Phoenix?
# Error
ArgumentError at GET /interview_Kit/new could not generate inputs for
:sub_sections from App.InterviewKit. Check the field
exists and it is one of embeds_one, embeds_many, has_one, has_many,
belongs_to or many_to_many
# This error is being shown when trying to render as a string in the method
link_to_sub_sections_field() below
# fields = render_to_string(__MODULE__, "sub_section.html", f: form)
# Schemas
schema "interview_kits" do
field :name, :string
field :description, :string
has_many :sections, AppSection
timestamps()
end
schema "sections" do
field :title, :string
timestamps()
belongs_to :interview_kit, App.InterviewKit
has_many :sub_sections, App.SubSection
end
schema "sub_sections" do
field :field_name, :string
belongs_to :section, App.Section
end
defmodule App.InterviewKitView do
def link_to_sub_section_fields() do
changeset = InterviewKit.changeset(%InterviewKit{sections: [%Section{sub_sections: [%SubSection{}]}]})
form = Phoenix.HTML.FormData.to_form(changeset, [])
fields = render_to_string(__MODULE__, "sub_section.html", f: form)
link "Add Sub Section", to: "#", "data-template": fields, id: "add_sub_section"
end
end
# sub_sections.html.eex
<%= inputs_for #f, :sub_sections, [multipart: true], fn fo -> %>
<div class="row">
<div class="col-md-11">
<%= input fo, :field_name %>
</div>
<div class="col-md-1">
<i class="fa fa-trash" aria-hidden="true"></i></h5>
</div>
</div>
<% end %>
# what I am trying to accomplish
interview_params = %{"_csrf_token" => "PDwZA==",
"_utf8" => "✓", "files" => "",
"interview_kit" => %{"description" => "<p>dsadasdasmoimoimadsads</p>",
"name" => "First Interview", "sections" => %{"0" => %{"name" => "sadasdsad"},
"sub_sections" => %{"0" => %{"field_name" => "sadasdsad"}}}}}
Issue was I was not reiterating over the sections form in my sub_section.html.eex
# sub_section.html.eex
# Correct way
<%= inputs_for #f, :sections, [multipart: true], fn fo -> %>
<div class="row">
<div class="col-md-11">
<%= inputs_for fo, :sub_sections, [multipart: true], fn po ->%>
<%= input po, :field_name %>
<% end %>
</div>
<div class="col-md-1">
<i class="fa fa-trash" aria-hidden="true"></i></h5>
</div>
</div>
<% end %>
# sub_section.html.eex
# Wrong way
<%= inputs_for #f, :sub_sections, [multipart: true], fn fo -> %>
<div class="row">
<div class="col-md-11">
<%= input fo, :field_name %>
</div>
<div class="col-md-1">
<i class="fa fa-trash" aria-hidden="true"></i></h5>
</div>
</div>
<% end %>
# section.html.eex
<%= inputs_for #f, :sections, [multipart: true], fn po -> %>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<%= input po, :name %>
</div>
</div>
<div class="panel-body">
<% inputs_for po, :sub_sections, [multipart: true], fn fo -> %>
<div class="row">
<div class="col-md-11">
<%= input fo, :field_name %>
</div>
</div>
<% end %>
<h5><%= link_to_sub_section_fields() %></h5>
</div>
</div>
<!-- END PANEL -->
</div>
<%= link "Remove Section", to: "#", id: "delete_section" %>
</div>
<% end %>
#interview_kit_view.ex
def link_to_sub_section_fields() do
changeset = InterviewKit.changeset(%InterviewKit{sections: [%Section{sub_sections: [%SubSection{}]}]})
form = Phoenix.HTML.FormData.to_form(changeset, [])
fields = render_to_string(__MODULE__, "sub_section.html", f: form)
link "Add Sub Section", to: "#", "data-template": fields, id: "add_sub_section"
end
interview_kit.js
handleAdd() {
$(document).on("click", "#add_section, #add_sub_section", function(e) {
console.log($(e));
e.preventDefault();
let time = new Date().getTime();
let template = $(this).data("template");
let uniq_template = template.replace(/\[0\]/g, `[${time}]`);
uniq_template = uniq_template.replace(/_0_/g, `_${time}_`);
$(this).after(uniq_template);
});
}
I am not sure I fully understand why I have to reiterate over the sections form in my partial but it gives me the correct params on submit I was looking for.
%{"_csrf_token" => "AlgJcnNQw==",
"_utf8" => "✓", "files" => "",
"interview_kit" => %{"description" => "<p>dsadsadas</p>",
"name" => "name",
"sections" => %{"1495809951376" => %{"name" => "sadsadas",
"sub_sections" => %{"1495809951376" => %{"name" => "field_param"}}}}}}
Any idea how to solve the following approach.
I have a form and want to display the entered data in a specific formtemplate before store it in the DB. If the entered data looks properly, the user can save the form.So I am searching for a way to display the entered data as a preview in a new window/tab first. With my code below I am not able to preview the form without saving the data in the databse. Also display the preview in a new window or tab is not possible. I guess there is no way to achieve this with php / laravel. I tried some onlick events, but no luck. As it seems like the route is prefered.
Any idea how to solve this?
My form looks like:
{{ Form::open(array('url' => 'backend/menubuilder/'.$id, 'method' => 'PUT'))}}
<section>
<div class="container">
<div class="row">
<div class="inputBox">
<div class="col-xs-12 col-md-6">
<h3>Montag</h3>
<div class="form-group">
{{Form::label('gericht_1_mo','Gericht 1')}}
{{Form::textarea('gericht_1_mo', Auth::user()->gericht_1_mo,array('class' => 'form-control'))}}
</div>
<div class="form-group">
{{Form::label('preis_1_mo','Preis', array('class' => 'col-md-6'))}}
{{Form::text('preis_1_mo', Auth::user()->preis_1_mo, array('class' => 'col-md-6'))}}
</div>
<div class="form-group mrgT55">
{{Form::label('gericht_2_mo','Gericht 2')}}
{{Form::textarea('gericht_2_mo', Auth::user()->gericht_2_mo,array('class' => 'form-control'))}}
</div>
<div class="form-group">
{{Form::label('preis_2_mo','Preis', array('class' => 'col-md-6'))}}
{{Form::text('preis_2_mo', Auth::user()->preis_2_mo, array('class' => 'col-md-6'))}}
</div>
</div>
</div>
</div>
</div>
</div>
{{Form::submit('update')}}
{{-- <input type="submit" name="preview" value="preview"> --}}
{{Form::close()}}
{{ Form::open(array('url' => 'backend/menubuilder/templatesview/'.$id, 'method' => 'POST'))}}
{{-- {{Form::submit('Preview',array('onClick' => 'target_blank'))}} --}}
<input onclick="newTab()" type="submit" name="preview" value="preview" >
{{Form::close()}}
My routes:
Route::get('backend/menubuilder/templates/{id}', 'MenuBuilderController#template');
Route::post('backend/menubuilder/templatesview/{id}', 'MenuBuilderController#preview');
My Controller:
public function preview($id)
{
$user = User::find($id);
$owner = (Auth::id() === (int) $id);
return View::make('backend/menubuilder/templatesview/tempone')->withUser($user)->withOwner($owner);
}
public function template($id)
{
$user = User::find($id);
$owner = (Auth::id() === (int) $id);
return View::make('backend/menubuilder/templates/tempone')->withUser($user)->withOwner($owner);
}