Return multiple checkbox from Custom html helper in mvc 3r - html-helper

Hey friends I am building questionnaire project in mvc 3. Here i need to return textbox, group of checkbox, radio buttons etc. I have build custom html helper for rendering those by checking its type from database. For single return it works fine but for multiple return it doesn't work.
as for example:
for single return,
return helper.CheckBox("chk"+question_id);
In some cases i need to return multiple checkbox, multiple text box and others.
As for example: In case of radio buttons, question type will be 2. Then from html helper i have to return 3 radio buttons
How can i proceed for it.

Hey Friends I got the solution for my problem.Simply using string builder and appending the multiple checkbox i return the value.
Here i have written the sample code which return label, checkbox and textbox.
I hope following code might be helpful to others also:
public static IHtmlString RenderQuestion(this HtmlHelper helper, int question_type)
{
var output = new System.Text.StringBuilder();
output.Append(helper.CheckBox("chk" + question_id));
output.Append(helper.Label(questiontext));
output.Append(helper.TextBox("txt"+question_id));
return helper.Raw(output.ToString());
}

Related

Select several checkboxes at once that seems to be images

Instead of manually selecting the check boxes of several pages,
I am using TamperMonkey to select all the check boxes with a small Javascript function.
The checkboxes get selected but the next step (SyncNow)for the procedure is greyed out.
I think it has to do with changing classes.
Is there another way to select the checkboxes with a 'click' via TamperMonkey?
or
How do I add an extra class that will hopefully not grey out the next step?
You can see the code that I have here:
https://codepen.io/Marina_2019/pen/dxXmZL
I tried this, and it did not work:
function selectAll(){
document.getElementById("AllInventorySelected").checked = true;
}
}, false);
This function worked:
checkThem([].slice.call(document.querySelectorAll('input[type="checkbox"]')));
function checkThem(nodes) {
nodes.forEach(function(n) { n.checked = true });
}
The problem is that the next after selecting all the check boxes are greyed out (unless I do it manually).
I noticed that a class gets added if I select the check boxes manually.
Code snippets are here:
https://codepen.io/Marina_2019/pen/dxXmZL

How can I detect the state of Content at View startup?

Lets assume I have created my own custom view for a Link content type. When the user adds a 2sxc Content app to a Pane, then picks the Content Type (Link) then my custom View, when it first starts up, how can I detect that a) the View does not use a Demo item vs. b) the View uses a demo item and is showing the Demo item vs. c) its not the first time and there is a real user added Content (Entity) in place?
I have done stuff like this for the a) case:
var link = AsDynamic(Data["Default"]).First();
then checked if it was null, but it looks like my View code never executes and instead I just see, "No demo item exists for the selected template."
If I do assign a demo, is there a more elegant way to know that the Entity I am handed as Content.First() or Data["Default"]).First() is a Demo item and now a user created Entity? Currently I am hard-coding the EntityId in the template and testing for that.
The template system does not render the template if there is no demo item (unless it's a template without a content-type).
When we need this, we have two ways
give the demo item a unique value in one of the fields and check for that in the template
check the demo-item ID on GUID and check for that (Content.EntityGuid == ...)
IsDemoItem property added in 2sxc 10.06
Dynamic Entity
If a Content Editor "Hides" the only Content Item, the anonymous user will then see a Demo Item where the item was. This is confusing and unexpected from the Content Editor's point of view (as well as the public/anonymous user). If anyone else runs in to it, here is the simple code snippet to add to the start of your view. Basically, if the current user is not logged in and the item to display is a demo item, exit the View w/o displaying anything.
if(!Request.IsAuthenticated) {
if(Content.IsDemoItem ?? false) {
return;
}
}
Best to put it near the start of your first #{} Razor block.
Note: this will not throw an error in 2sxc prior to 10.6.x (because of the "?? false"), but it will not work either.

How to make quill editor required?

How to make the quill editor field required? The editor gets rendered into a div, but it isn't clear if there is a way to make the field/editor required when the form submits.
As you wrote, Quill works with a div and not with a form element so it can't help you with form validation.
You'll need to check manually if the editor's content is empty, prevent the user from submitting the form and show a message that this field is required.
You can copy quill contents to a hidden input element before submitting the form as shown in this example.
A custom form control is also a good way to go. You can try to workaround with Quill's event handler and getting the value of the form.
Then a custom form validator is also possible.
Check : https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html
I've been trying to work around exactly this problem too today, using Python for back-end and a hidden form-field (name='editor') to get the value from the quill container to the back-end. Ended up with not actually really a validator but working about the same:
if request.form['editor'] == '\"<p><br></p>\"':
flash("You cannot send in empty posts!")
return redirect(CURRENT PAGE)
else:
CODE EXECUTED IF EDITOR IS NOT EMPTY
Not sure what you're doing with the input on the editor or whether you're even using Python for backend but I hope this helps. "<p><br></p>" is what the console told me the standard input on empty submission was when getting the information out of the editor.
Good luck!
const yourText = '<div><br></div>';
const htmlTagsToRemove = ['<div>', '</div>', '<br>'];
function removeHtmlTags(data) {
let text = data;
htmlTagsToRemove.forEach(it => {
text = text.replace(it, '');
});
return text;
}
const newText = removeHtmlTags(yourText);
console.log(newText);

how do it associate a dropdown-menu input to another databasetable with laravel

I've got a form that fills a table in my database. Now i've added a dropdown to that form where the you can choose a user that should be associated to the rest of the form input. But im still unable to associate the dropdown to the user_id in the table.
I hope i made my issue clear,
The code that i just in my controller was :
public function store(PartRequest $request)
{
Project::find(Input::get('project'))->parts()->create($request->all());
return redirect('parts');
}
where my dropdown had classname:project

dropdown list atk4 quicksearch

i try to populate a dropdown menu for quicksearch in mvcgrid my code is:
$g = $this->add('MVCGrid');
$g->setModel('materiale');
$g->addPaginator(25);
$s = $g->addQuickSearch(array('nome_mat'));
$value_list = array(
1=>'Granito',
2=>'Marmo'
);
$s->addField('dropdown','tipo_mat','Tipo_mat: ')->setValueList($value_list);
The dropdown list appear on quick search form.
My db field is tipo_mat, but when i click quicksearch button nothing uppens, can someone help me plase.
Thank's
You will find that the Quicksearch is nothing more that a simple form, which applies condition to your grid when submitted. In theory, you could have a standard form sitting in there doing the same thing:
$search = $g->add('Form',null,'quick_search',array('form/quicksearch','form'));
$search->addFiled('dropdown','tipo_mat')
->setValueList($value_list)
->set($_GET['tipo_mat']);
$search->addField('search','q')
->set($_GET['q']);
// Handle submit of form, reload grid with AjAX, pass values as arguments
if($search->isSubmitted()){
$grid->js()->reload($search->getAllData())->execute();
}
// If values are passed, use them
if($_GET['q'])
$grid->dq->where('name like','%'.$_GET['q'].'%');
if($_GET['tipo_mat'])
$grid->dq->where('foo',$_GET['tipo_mat']);
The "Filter" and "QuickSearch" classes help you with saving search values but you must not be afraid to look into their source and create your own QuickSearch class which can apply parameters properly.
Perhaps using Filter in your case is better than quick search, because of how "applyDQ" is handled:
https://github.com/atk4/atk4/blob/master/lib/Filter.php#L62

Resources