I Have this in my controller
ViewBag.list = new SelectList(db.ListOfDB, "Value", "Text");
I need to create a Select, but without using the #Html.DropDownList I try to use this:
<select id="mylist"> ??? (selectitem) #ViewBag.list ??? </select>
How create select based from Viewbag, but not use Html.Helper
You can pass your list to the view on your model. You could then do
<select id="myList">
#foreach(var item in Model.myList)
{
<option value="#item.Value">item.Name</option>
}
</select>
#{
ViewBag.Title = "";
Layout = "~/Views/Shared/_LayoutLanding.cshtml";
List<SelectListItem> list = ViewBag.list;
}
#for(int i = 0; i < list.Count; i++)
{
<option value="#list[i].Value">#list[i].Text</option>
}
After many attempts, this one worked for me
This one in the Controller -
ViewBag.ilist = new SelectList(db.tblPersons.Where(d => d.PersonTyp == "SUPPLIER").ToList(), "slno", "PersonName");
'slno' being the Id column and 'PersonName' being the 'Data' column
Then in Razor page (Without HTML helpers)
<select id="dpdnperson" name="dpdnperson" class="dropdown btn bg-gradient-primary" style="color:white; width:100%" Font-Size="Medium">
<option>-- SELECT --</option>
#foreach (var item in ViewBag.ilist)
{
<option value="#item.Value" >#item.Text</option>
}
</select>
Related
I am very new to React so I am still learning a lot. No matter what I do, the onSelect just does not seem to work. I made a simple function that it should call. You can tell it's been called via the console.log but in the browser when I look at the console it just does nothing.
Here is the code for the dropdown:
import React,{useState} from 'react';
import SEPractices from "../dummydata/SEPractices"
const optionItems = SEPractices.map((SEPractice) =>
<option key={SEPractice.practice}>{SEPractice.practice}</option>
);
const Dropdown = () => {
const handleSelect=(e)=>{
console.log("Inside");
}
return (
<div>
<select onSelect={handleSelect}>
<option Default hidden>
Select an SE Practice
</option>
{optionItems}
</select>
</div>
)
}
export default Dropdown;
Try using onChange
<select value={selectValue} onChange={handleSelect}>
<option Default hidden>
Select an SE Practice
</option>
{optionItems}
</select>
And handleSelect like this:
const [selectValue, setValue] = useState("")
cosnt handleSelect = (e) => {
setValue(e.target.value);
}
<select value={selectValue} onChange={handleSelect}>
<option value="dummyData">
Select an SE Practice
</option>
{optionItems}
</select>
and don't use the Default and hidden, React will take care of default value why specifying value={selectValue} in element.
Also, we need to pass the value to the <option>, it will track based on the value.
I have a form with many dropdownlist and i want to exclude the none selected ones from appearing in the querystring when the form is submitted.
So can i use some module or filter to change this behavior.
Ex:
When i search for test the url will be
/someaction?q=test&select1=&select2=
The required url is :
/someaction?q=test
<form action="/search" action="Get">
<label>Search term <input name="q"></label>
<select id="select1" name="select1">
<option value="1">option 1</option>
</select>
<select id="select2" name="select2">
<option value="1">option 1</option>
</select>
<input type="submit">
</form>
Since you're using GET method for form action, you can handle submit event to prevent normal submit and strip out empty values using replace() function with regex, then use location.href to redirect into target URL:
$('form').submit(function (e) {
e.preventDefault();
var queryString = $(this).serialize().replace(/&?[\w\-\d_]+=&|&?[\w\-\d_]+=$/gi, "");
url = this.getAttribute('action') + (queryString.length > 0 ? "?" + queryString : "");
// returns URL /search?q=something when both select elements are empty
location.href = url;
});
Or disable the select elements without values on-the-fly using attr() or prop() to prevent them used in query string, using normal form submit event:
$('form').submit(function () {
$('select').each(function () {
if ($(this).val() == '') {
$(this).prop('disabled', 'disabled'); // or prop('disabled', true)
});
});
I have 6 selects wrap in their own div each, and I want to hide the whole div, if the select is blank.
<div>
<select>
<option></option>
<option>1</option>
</select>
</div> <--- Hide this div if blank option is chose.
Are you after something like this? This is hiding a separete div based on your selection. In your question, you are hiding the selection itself if it is blank. If you do that, how can you change your selection, once select has disappeared?
var checkTheCat = function(index) {
if( !index ) hideTheCat();
else showTheCat();
}
var hideTheCat = function() {
document.getElementById("toHide").style.display = 'none';
}
var showTheCat = function() {
document.getElementById("toHide").style.display = 'block';
}
<div id="toHide">
<img src="https://i.ytimg.com/vi/tntOCGkgt98/maxresdefault.jpg" style="height:100px;">
</div>
Please select below:<br>
<select id="selection" onChange="checkTheCat(this.selectedIndex);">
<option>Blank option</option>
<option>The Cat</option>
<option>Another non-blank option</option>
<select>
Newbie to Node.js here:
What is an easy way to make dynamic dropdowns in node.js?
Basically, I have two tables: Skill and Skill_Category .
I want to select from the Skill_Category and be presented with the associated Skill.
I would assume I would need to use some template engine (to render in a webpage).
I tried researching a good amount on google, but didn't turn up anything that helped me.
If anyone can point me in the right direction?
Thank you!
So one dropdown will cause the other to show. Unless the second dropdown has hundreds of options you won't want to make a separate server side request to get it in. This means your logic should all be in the browser/client side.
This means you want your "Skill_Category" select box to have a JS function called to hide the current "Skill" select box and show the newly chosen "Skill" select box. They will all be rendered in html by your templating, but only one will ever be shown (display:block) while the others are hidden (display:none).
Sample HTML:
<select id="skill_category">
<option value="communication">Communication</option>
<option value="teamwork">Team Work</option>
<option value="technical">Technical</option>
</select>
<select class="skill" id="communciation">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="skill" id="teamwork">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
<select class="skill" id="technical">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
Sample Jquery code:
$('#skill_category').on('change',function(){
$('.skill').hide()
$('#'+this.value).show()
});
Update:
If you have a large list of options for the secondary select box then you can make an ajax (HTTP GET) request, and returning the lsit of dropdowns from your server as JSON.
You will probably have one of two scenarios: all of you skills in a static JSON file, or saved in a database.
Your node code will look like:
app.get('/skill_category/:skill', function(req, res){
//JSON file in the /public/skills directory
res.sendFile(__dirname + '/public/skills/'+req.params.skill+".json");
//or some database lookup followed by a json send:
var skills = someDatabaseLookup();
res.json(skills);
});
HTML
<select id="skill_category">
<option value="communication">Communication</option>
<option value="teamwork">Team Work</option>
<option value="technical">Technical</option>
</select>
<select id="skill">
</select>
while the jquery will now be:
$('#skill_category').on('change',function(){
$.get('skill_category/'+this.value,function(data){
for(var j = 0; j < length; j++)
{
$('#skill').contents().remove();
var newOption = $('<option/>');
newOption.attr('text', data[j].text);
newOption.attr('value', data[j].value);
$('#skill').append(newOption);
}
});
});
Do note this code is untested but should work
For search i use liferay-ui:search in the dockbar. User should be able to define search scope (specific private page) by choosing it from dropdown list.
How can i implement search on specific private page?
And 1 more question. Seems it's a bug, but user is able to search only while he is on specific private page. If he move to another page - search button is "disabled" - nothing happens when he clic it. For admin account everything works fine - i am able to search being on any page.
Thanks!
OK. 1st step was to place hook on [b]html/taglib/search/start.jsp[/b]. I passed an extra id parameter to define on which private page i gonna search.
<input name="<%= namespace %>keywords" size="30" title="<liferay-ui:message key="search" />" type="text" value="<%= HtmlUtil.escapeAttribute(keywords) %>" />
<input name="<%= namespace %>groupid" value="0" type="hidden" />
<select name="<%= namespace %>scopeId" title="<liferay-ui:message key="scope" /> ">
<option value="0" <%= selected == 0 ? "selected" : ""%>><liferay-ui:message key="everything" /></option>
<option value="1" <%= selected == 1 ? "selected" : ""%>>Новости</option>
<option value="2" <%= selected == 2 ? "selected" : ""%>>Сотрудники</option>
<option value="3" <%= selected == 3 ? "selected" : ""%>>Новому сотруднику</option>
<option value="4" <%= selected == 4 ? "selected" : ""%>>Корпоративные правила</option>
<option value="5" <%= selected == 5 ? "selected" : ""%>>Продукты</option>
<option value="6" <%= selected == 6 ? "selected" : ""%>>Wiki</option>
<option value="7" <%= selected == 7 ? "selected" : ""%>>События</option>
<option value="8" <%= selected == 8 ? "selected" : ""%>>Форум</option>
</select>
2nd step was to hook on [b]html/portlet/search/main_search.jsp[/b]. There i was going to filter [b]ALL[/b] search results and display only those which needed by request from [b]select field[/b]. It's OK for non instanceble custom portlets with have different id, i just filter by portletId and display result.
Hits hits = indexer.search(searchContext);
List<Document> documents = new ArrayList<Document>();
documents = hits.toList();
...
if (documents.size() != 0) {
List<Document> toDelete = new ArrayList<Document>();
for (Document document : documents) {
String id = document.getPortletId();
id = document.get(Field.PORTLET_ID);
switch (scopeId) {
case 0:
break;
case 1:
if (!id.equals(NEWS_PORTLET_ID)) {
toDelete.add(document);
}
break;
....
if (toDelete.size() != 0) {
documents.removeAll(toDelete);
hits.setDocs(documents.toArray(new Document[documents.size()]));
if (documents.size() == 0) {
hits.setLength(0);
}
}
All fine. But 3 of my pages all have asset publisher portlet (portletId = 15), so if i filter by portlet id - i will get results from all 3 pages. Maybe i can get instance id of portlet which document belongs to. Or maybe there is some other way to do search.
Atm i try to implement my CustomJournalArticleIndexer. The idea is Indexer adds field containing portlet's instance id. So later in main_search.jsp i can do something like document.getPortletInstanceId and compare it with a constant paired with scopeId of my request.
Any suggestions here?
Thanks and... from Russia with love!