Kendo UI External Editing Form - kendo-asp.net-mvc

I'm Working on a project in which i have implemented Kendo Grid and when i click the edit button a popup for editing is displayed. But what i want is a separate panel alongside of kendo grid which i have made using [bootstrap][1] and i want to populate it with the editing detail of particular row clicked in the Kendo grid. I have attached the image below to give you an idea what i want. the help bordered area is where i want to populate it showing editable detail of selected row. Any Help??
#(Html.Kendo().Grid<UserItem>()
.Name("usergrid")
.HtmlAttributes(new { style = "width:100%" })
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.EmailAddress);
columns.ForeignKey(o => o.RoleId, (System.Collections.IEnumerable)ViewData["Roles"], "Id", "Description")
.Title("Role");
columns.ForeignKey(o => o.SystemRoleId, (System.Collections.IEnumerable)ViewData["SystemRoles"], "Id", "Description")
.Title("Sys Role");
columns.ForeignKey(o => o.TimeZoneId, (System.Collections.IEnumerable)ViewData["TimeZones"], "Id", "Description")
.Title("Time Zone");
columns.Bound(e => e.DefaultPageSize).Title("Default Page Size");
columns.Bound(o => o.IsActive).Title("Is Active");
columns.Bound(o => o.LastLoginDate).Format("{0:d}").Title("Last Login");
columns.Command(command => { command.Edit().Text("Edit"); });
})
.ToolBar(toolbar =>
{
toolbar.Template(#<text>
<div class="toolbar">
<span id="divCompany" style='#(roleName == Constants.SystemRoles.FifthMethod?"":"display:none;")'>
<label class="category-label" for="ddlCompany">Companies :</label>
#(Html.Kendo().DropDownList()
.Name("ddlCompany")
.DataTextField("Name")
.DataValueField("Id")
.AutoBind(true)
.Events(e => e.Change("CompanyChange"))
.HtmlAttributes(new { style = "width: 150px;" })
.BindTo(ViewBag.Companies)
.Value(Convert.ToString(ViewBag.CurrentCompanyID))
)
</span>
#Html.Kendo().Button().Name("btnNewUser").Content("New User").HtmlAttributes(new { #class = "k-button k-button-icontext k-grid-add pull-right" })
<button type="button" data-toggle="modal" data-target="#importUser-pop" class="k-button k-button-icontext pull-right">Import Users</button>
</div>
</text>);
})
.Editable(editable =>
{
editable.Mode(GridEditMode.PopUp);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(c => c.UserId);
model.Field(c => c.LastLoginDate).Editable(false);
})
.Create(create => create.Action("User_Create", "User").Data("GetCompanyId"))
.Read(read => read.Action("User_Read", "User").Data("GetCompanyId"))
.Update(update => update.Action("User_Update", "User"))
)
.Pageable()
.Sortable()
.Filterable()
.Events(e => e.Edit("grid_Edit"))
)

A complete example already exists in Kendo Docs how to edit records using external forms
A mvvm bounded section <div id="editForm"> to grid row using kendo.bind($("#editForm"), viewModel)

Related

Admin page Product gallery livewire full page multi image upload

I'm trying to make a product gallery for the e-commerce page on the admin side, while uploading bulk products, the row in the table provides two times again.
$this->validate([
'title' => 'required',
'NewsImage.*' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'product_id' => 'required',
]);
if(!empty($this->NewsImage)) {
foreach ($this->NewsImage as $image) {
$imageName = $image->hashName();
$image->store('public/products');
Image::create([
'title' => $this->title,
'image' => $imageName,
'product_id' => $this->product_id,
]);
}
}
$this->modalFormVisible = false;
$this->reset();
$this->resetFields();
#if(count($NewsImage))
#foreach($NewsImage as $image)
<td class="px-6 py-4 text-sm whitespace-no-wrap">
<img class="w-8 h-8 rounded-full" src="{{ \Illuminate\Support\Facades\Storage::url($Image->image) }}" />
</td>
#endforeach
#endif
I want to list it side by side but I couldn't do it can you help me thank you very much in advance
I shared a related photo, I'm trying to sort the image side by side, but when I add it, it adds an extra row.

Displaying search field with omines/datatables-bundle

Im new to omines/datatables-bundle and I have problem displaying search.
I was studying documentation and was not able to get it working.
Ive created a table like this
$table = $dataTable->create()
->add('street', TextColumn::class, ["label" => "Street", "searchable" => true, "globalSearchable" => true])
->add('houseNumber', TextColumn::class, ["label" => "House number", "searchable" => true])
->add('postal', TextColumn::class, ["label" => "Postal Code", "searchable" => true])
->add('city', TextColumn::class, ["label" => "City", "searchable" => true])
->add('country', TextColumn::class, ["label" => "Country", "searchable" => true])
->createAdapter(ORMAdapter::class, [
'entity' => CustomAddress::class,
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('sales_request/add_custom_address.html.twig', ['datatable' => $table]);
Also, in my twig template
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true });
});
</script>
The datatable works fine, sorting is working etc, but I dont see the search input field.How should I configure it to display it?
For anyone finding this issue by searching - it's actually a configuration issue we didn't document well enough.
The default Symfony recipe sets the DataTables native dom option to a sane default, but it omits the search field as it's not universally required. In general one should configure the dom value correctly for the intended result.
For more information see https://github.com/omines/datatables-bundle/issues/57#issuecomment-453529328
You can just add option dom : 'Bfrtip'
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true, dom: 'Bfrtip' });
});
</script>

Yii2 ActiveForm custom template for checkbox field

I'm looking to use a template for my checkboxList.
That's the properties i want to apply
class="switch" checked data-on-text="ON" data-off-text="OFF" data-on-color="teal"
<?php $form = ActiveForm::begin(); ?>
<ul class="list-unstyled">
<li>
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(ArrayHelper::map(Permission::find()->all(),'id', 'code')) ?>
</li><br>
</ul>
<div class="form-group">
<?= Html::submitButton($modelUserPermission->isNewRecord ? 'Create' : 'Update', ['class' => $modelUserPermission->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'value'=>'Create', 'name'=>'submit']) ?>
</div>
<?php ActiveForm::end(); ?>
<?= $form->field($model, 'recomended_by_user', ['template'=>'<div class="control-group">
<label class="control control--checkbox checkbox-small-text">Recomended by user
{input}
<div class="control__indicator"></div>
</label>
</div>'])->textInput(['class'=>"",'type'=>'checkbox'])?>
Use like this for custom Checkbox template
Answer provided by Bizley is correct, but here is one more alternate way you can try if you want.
<?php
$items_array = ArrayHelper::map(Permission::find()->all(),'id', 'code');
echo $form->field($model, 'id_permission')->checkboxList($items_array, [
'items' =>
function ($index, $label, $name, $checked, $value) {
return Html::checkbox($name, $checked, [
'value' => $value,
'label' => '<label for="' . $label . '">' . $label . '</label>',
'labelOptions' => [
// you can set label options here ],
],
]);
}, 'itemOptions' => ['class' => 'switch',
'data-on-text' => 'ON', 'data-off-text' => 'OFF', 'data-on-color' => 'teal'],
'separator' => false,]);
?>
If you want these properties in every checkbox (like Insane Skull asked) use itemOptions option.
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(
ArrayHelper::map(Permission::find()->all(),'id', 'code'),
[
'itemOptions' => [
'class' => 'switch',
'data' => [
'on-text' => 'ON',
'off-text' => 'OFF',
'on-color' => 'teal'
],
],
]
) ?>
Since it's ActiveField widget in order to get all checkboxes checked you have to pass array to $modelUserPermission->id_permission with all the IDs.

how to insert a button to open modal window inside a simple_form

using Rails 4.1.6 , simple_form 3.1.0.rc2, Bootstrap 3
I am trying to set a button inside my simple_form to open a Bootsrap modal window to perform a js user selection
my simple form is the following :
.form-inputs
.row
.col-sm-8.col-md-8.col-lg-8
- if ((current_user.has_role? :superadmin) || (current_user.has_role? :media_admin))
.form-group
%button.btn.btn-default{:'data-toggle' => "modal" , :'data-target' => "#myModal"}
Select Owner of album
= f.input :user_id, as: :hidden, input_html: {value: current_user.id}
.row
.col-sm-8.col-md-8.col-lg-8
= f.input :title, :label => t(:title, scope: :album).capitalize
= f.input :description, as: :text, :label => t(:description, scope: :album).capitalize
and I added a standard bootstrap modal test
#myModal.modal.fade{ tabindex: "-1" ,role: "dialog", :'aria-labelledby' => "myModalLabel", :'aria-hidden' => "true"}
.modal-dialog
.modal-content
.modal-header
%button.close{type: "button", :'data-dismiss' => "modal" }
%span{:'aria-hidden' => true}
×
%span.sr-only
Close
%h4#myModalLabel.modal-title
Modal Title
.modal-body
= "Modal body"
.modal-footer
%button.btn.btn-default{type: "button", :'data-dismiss' => "modal" }
Close
%button.btn.btn-primary{type: "button", :'data-dismiss' => "modal" }
Save changes
When I hit the 'Select Owner of album' button, it acts as the submit one and try to save the form data.... not opening the modal form
Did I miss anything ?
I should rather use a link tag with button class....
.form-group
%a.btn.btn-success{href: "#", :'data-toggle' => "modal" , :'data-target' => "#myModal"}
Select Owner of album

Cakephp 3 multiple custom template formhelpers

So I'm at work (working with sensitive data might I add for posterity's sake), and the powers that be decide we need to use the all powerful and least documented new tool by Cakephp 3.0 (beta at this time).
Edit: My goal is to create several different templates for forms to call through the formhelper template or input methods. There really isn't much of an a good example for this.
Customizing the Templates FormHelper Uses:
As seen in the book(and nowhere else on the internet anywhere) the very short documentation is thus:
http://book.cakephp.org/3.0/en/core-libraries/helpers/form.html#customizing-the-templates-formhelper-uses
The site says you can use the template method and then give a vague "use":
$myTemplates = [
'inputContainer' => '<div class="form-control">{{content}}</div>',
];
$this->Form->templates($myTemplates);
Then it says you can use the input() method for which it gives no example.
And last but not least the custom template FormHelper should allow you to "make" or "create" as many of these custom formhelpers as you wish, but they give no example use of how to do that!? lulwut?
I can easily use it once like their example, but where's the power in a single custom template? That doesn't do me anygood.
So by a new possible solution I try and get a new error.
I get this error(within my view)(from the following code):
Fatal Error
Error: Class 'Configure' not found
//within bootstrap.php
Configure::write('templates', [
'shortForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-4"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-4"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',],
'longForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-6"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-6"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',],
'fullForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-10"><input type="{{type}}" name="{{name}}" {{attrs}} /> </div>',
'select' => '<div class="col-md-10"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',]
]);
//within my view
<?php
$this->Form->templates(Configure::read('templates.shortForm'));
?>
Old Update: I added
use "Cake\Core\Configure;"
in my view and everything works great, but I would like to add this to the appropriate file in the hierarchy so that I don't have to add that to every view,
that is unless of course it causes efficacy issues for the entire app as a whole. Does anyone know which file it should go in? Regards and TIA!
Newest Update: I just figured it out. So simple! check my answer below! Hope this helped someone
What this fix does is allow you to have custom template forms (from cakephp 3!!!!) using bootstrap. If you want to set sizes using the form helper and all of it's goodness (security and what not).
Jose Zap of Cakephp told me to try bootstrap plugins and widgets and what not, but the real way to do this should have been this:
Step 1: Create config/templatesConfig.php and add your custom form stuff.
<?php
$config = [
'Templates'=>[
'shortForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-4"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-4"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',],
'longForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-6"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-6"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',],
'fullForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-10"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-10"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',]
]
];
Step 2: From your controller inside the method for the correct view call this line.
Don't forget add this on the top of your controller
use Cake\Core\Configure;
$this->set('form_templates', Configure::read('Templates'));
Step 3: Add this within the bootstrap.php file
// Load an environment local configuration file.
// You can use this file to provide local overrides to your
// shared configuration.
Configure::load('templatesConfig','default'); //fixed
Step 4(finally): Add this line with the template name you want Bam!.
<?php $this->Form->templates($form_templates['shortForm']); ?>
Let's say you need all inputs to use a custom markup in a form to show the label after the input (default is before) and a different class for the hardcoded error-message for errors:
$this->Form->create($entity, ['templates' => [
'formGroup' => '{{input}}{{label}}',
'error' => '<div class="error">{{content}}</div>'
]]);
If you want to only customize a single input, pass the same 'templates' key to the FormHelper::input() options like so:
$this->Form->input('fieldname', ['templates' => [
'formGroup' => '{{input}}{{label}}',
'error' => '<div class="error">{{content}}</div>'
]]);
If you need to define multiple templates and re-use them whenever you want, here's something you can try (mind I am writing it here, never used it before):
// in bootstrap (as this is a config i believe
Configure::write('templates', [
'foo' => [....],
'bar' => [....]
]);
// in any view
$this->Form->templates(Configure::read('templates.foo'));
$this->Form->create(...);
....
You could also create your own helper and define the templates there, etc.
It really all depends on what you want to achieve but that should give you a good understanding of how templates work (not just in forms by the way).