Show/Hide Form Fields in Squarespace - java

I am trying to show/hide form fields in a Squarespace form based upon the value selected in a dropdown menu. The dropdown menu has a list of values from 1-10. The intent is to display 2 form fields for each number selected from the dropdown menu. For value 1, I want the form fields titled "Serial Number" and "Confirm Serial Number" to ALWAYS be displayed. For value 2, I want to show "Serial Number 2" and "Confirm Serial Number 2". And so on for values 3-10.
Here is a screenshot of the form as it is now with everything displayed.
enter image description here

You can get the serial element with document.getElementById(`serial-input-${index}`)
You can get the serial confirm element with document.getElementById(`serial-input-confirm-${index}`)
<p>Number of products</p>
<select id="select" onChange="create.input()"></select>
<div id="input"></div>
const create = {
select: () => {
let select = document.getElementById('select')
// Create 1-10 number of products
new Array(10).fill(0).forEach((x, i) => {
let option = document.createElement('option')
option.innerHTML = (i+1)
option.value = (i+1)
select.appendChild(option)
})
},
input: () => {
let input = document.getElementById('input')
let select = document.getElementById('select')
console.log(select.value)
// Remove all child
input.innerHTML = ''
// Create the same number of input has you select in select ...
const size = parseInt(select.value, 10)
new Array(size).fill(0).forEach((x, i) => {
console.log(i)
let p_input = create.p_input(i)
p_input.forEach(x => input.appendChild(x))
})
},
p_input: index => {
let name = `erial number` + (index > 0 ? ' ' + (index+1) : '')
let serial_p = document.createElement('p')
serial_p.innerHTML = 'S' + name
serial_p.id = 'p-serial-' + index
serial_p.class = 'p-serial'
let serial_p_confirm = document.createElement('p')
serial_p_confirm.innerHTML = 'Confirm s' + name
serial_p_confirm.id = 'pc-serial-' + index
serial_p_confirm.class = 'pc-serial'
let serial_input = document.createElement('input')
serial_input.type = "text"
serial_input.id = "serial-input-" + index
serial_input.class = 'serial-input'
let serial_input_confirm = document.createElement('input')
serial_input_confirm.type = "text"
serial_input_confirm.id = "serial-input-confirm-" + index
serial_input_confirm.class = 'serial-input'
return [serial_p, serial_input, serial_p_confirm, serial_input_confirm]
}
}
create.select()
create.input()
for exemple here its what i get when i click on 5.

Related

how to added dynamic query params using string in Angular 7?

Currently I have multiple dropdown field in screen. when selected dropdown value pass in the query param so I want to create dynamic query param added. my code is below
// this is one of the dropdown value
if (this.SearchText) {
query += 'q:' + SearchText + ',';
}
// this is the second one of dropdown value
if (this.MakeId) {
makename = this.SpaceToDash(this.MakesList.find(x => x.Id === +this.MakeId).Name);
navigateUrl += '/' + makename;
query += 'merk:' + this.MakeId + ',merkname:' + makename + ',';
}
this.router.navigate([ navigateUrl ], { queryParams: { query } });
So if "MakeId" is not dropdown value then should not added in "queryParams" so how can I do it. Above solution is not working it.
Apply solution for Dynamically create query Params in Angular 2 but it is not fit in my requirement. So can you help me anyone in it?
QueryParams should take an Object not a string ,
so you can do it by this way
let query = {};
// this is one of the dropdown value
if (this.SearchText) {
query['q'] = SearchText;
}
// this is the second one of dropdown value
if (this.MakeId) {
makename = this.SpaceToDash(this.MakesList.find(x => x.Id === +this.MakeId).Name);
navigateUrl += '/' + makename;
query['merk'] = this.MakeId;
query['makename'] = makename;
}
this.router.navigate([ navigateUrl ], { queryParams: query });

get specify word from string php codeigniter

I have an input for search ,
i search for "res"
<input type="text" name="search"I/>
i use Like method to get search results,
$txt = $this -> input -> post("search");
$this -> db -> like('title', $txt);
if ($sql = $this -> db -> get('ads') -> result()) {
$data['posts'] = $sql;
print_r($sql);
}
and get this results :
some text restaurant and other
some text result
my resume
i want to show the liked word
extract the word from strings and remove other texts
i want this :
restaurant
result
resume
You can split the found string into an array (explode) and then search this array with the given string (preg_grep) and output the found strings.
<?php
$searchString = "/res/";
$foundString = "some text restaurant and other";
$explode = explode(" ", $foundString);
$searched = preg_grep($searchString, $explode);
foreach($searched as $item) {
echo $item . " ";
}

Getting search count in java from an array after comparing against the user input

I am supposed to create an output similar to this:
I have organized my data into an array. To put it simply, I have organized it to
with 8 different POIBook with its individual data.
POIBook[i] = new POI(Type, Place, Rating)
I have no problems calling the right array according to the user input into a JOptionpane display.
However, I have problems trying to determine the total number of search and the search result the user is currently at. Eg. Search 1 of 3
How do I get the total number of the search result and the number the user is currently at?
Edit: To add in the context of the question.
The user will enter a search query in JOptionpane and it will search and return the array containing the search result. For example, searching for "Excitement" will return POIBook[4] , [5] and [6] as a JOptionpane display and as per the output expected in the picture above.
Need help on the following:
How do I show that that 'Search Result - 1/3' when POIBook [4] is returned? and 'Search Result - 2/3' when POIBook[5] is returned etc.?
At the point of display, we will need to know there are 3 results of "excitement" type and it is currently showing the 1st result out of 3.
public static void dataPOI() {
POIBook[0] = new POI("Sightseeing", "River Safari","Wildlife, Panda Bear, Cruise",4.0);
POIBook[1] = new POI("Sightseeing", "Singapore Flyer","Fly!",3.5);
POIBook[2] = new POI("Sightseeing", "Gardens by The Bay","Flower Dome, Cloud Forest",3.5);
POIBook[3] = new POI("Shopping", "Orchard Road","Ion, Mandarin Gallery",4.0);
POIBook[4] = new POI("Excitement", "Universal Studios","Battlestar Galactica, Puss in Boots",4.5);
POIBook[5] = new POI("Excitement", "Marina Bay Sands","Casino, Sky Park Observation Deck",4.0);
POIBook[6] = new POI("Excitement", "Resorts World Sentosa","Trick Eye Museum, Adventure Cove",4.5);
POIBook[7] = new POI("Night Life", "Night Safari","Wildlife, Tram Ride",4.5);
}
My code is as follows.
public static void search() {
String search = JOptionPane.showInputDialog(null, "Please enter your type of attraction", "Place of Interest",
JOptionPane.QUESTION_MESSAGE);
for (int i = 0; i<POIBook.length; i++) {
if(search.equalsIgnoreCase(POIBook[i].type)) {
Object[] options = { "Next >", "Return to Menu" };
int select = JOptionPane.showOptionDialog(null, "Place of interest " + (i+1) + " of 8\n" + POIBook[i].display() +
"\nPress Next for next Place of Interest \n" + "To return, press Return to Menu \n", "Display Places of Interest in Sequence",
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE, POIBook[i].icon, options, options[1]);
if (select == 1) {
return;
}
}
}
}

Google Maps MySQL Map with HTML InfoWindow

I have scriptet me a maps with markers based on a MySQL Table.
The position is in the Table.
Now, i would like to write with HTML in the InfoWindow, because it not show HTML on the InfoWindow on the Map.
downloadUrl('inc/map_bridge.php', function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName('marker');
Array.prototype.forEach.call(markers, function(markerElem) {
var name = markerElem.getAttribute('name');
var ide = markerElem.getAttribute('id');
var desc = markerElem.getAttribute('beschreibung');
var type = markerElem.getAttribute('art');
var link = '<p>Klicke für weitere infos: Hier';
var point = new google.maps.LatLng(
parseFloat(markerElem.getAttribute('lat')),
parseFloat(markerElem.getAttribute('lng')));
var infowincontent = document.createElement('div');
var strong = document.createElement('strong');
strong.textContent = 'ID' + ide + ': ' + name
infowincontent.appendChild(strong);
infowincontent.appendChild(document.createElement('br'));
var text = document.createElement('text');
text.textContent = desc + link
infowincontent.appendChild(text);
var icon = customLabel[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
label: icon.label
});
marker.addListener('click', function() {
infoWindow.setContent(infowincontent);
infoWindow.open(map, marker);
});
});
});
}
It show only so:
show example picture
the following i have in the MySQL-Table
first line<br>second line
If 'beschreibung' were the result of SELECT SQL, the reason is escaped SELECT
SQL result.
(I'm in short of reputation, so write in answer form.)

How to access duplicate values in simple combo box in ExtJs

I have a SimpleComboBox in GUI which contains some duplicate items also. Assume there are 3 items which is same as "domain". When i select second "domain" or third "domain", the selected item and selected index is always pointing to first occurance of "domain". How can i correct, so that the selected index/item is right one, instead of first occurance of item?
ComboBox with duplicate values:
When i select "domain" at fourth occurence it will always pointing the first occurance of "domain".
Output:
When i select the "192.168.1.30" at last occurenece, it will point the first occurance of "192.168.1.30".
Please any one help me.
private SimpleComboBox<String> domainName = new SimpleComboBox<String>();
domainName = WidgetUtil.getStringCombo("Domain Name", 12, true, domainNameList, null);
domainName.addSelectionChangedListener(getReportSelectionListener());
domainName.setForceSelection(true);
domainName.setTriggerAction(TriggerAction.ALL);
private Button New, add, remove;
New = WidgetUtil.getButton("New", "new", "");
New.addSelectionListener(buttonAction());
thirdLayoutContainer.add(New);
add = WidgetUtil.getButton("Add", "add", "");
add.addSelectionListener(buttonAction());
add.setStyleAttribute("paddingTop", "10px");
thirdLayoutContainer.add(add, formData);
remove = WidgetUtil.getButton("Remove", "remove", "");
remove.addSelectionListener(buttonAction());
public void componentSelected(ButtonEvent ce){
String domain_name = null;
if (ce.getComponent().getId().equals("remove")){
System.err.println("Clicked remove button...");
domain_name = domainName.getRawValue();
domainNameList.remove(domain_name);
systemDetailsMap.remove(domain_name);
systemDetailsMap.remove(domain_name + "_USER_NAME");
systemDetailsMap.remove(domain_name + "_HOST_NAME");
systemDetailsMap.remove(domain_name + "_PASSWORD");
domainName.removeAll();
domainName.add(domainNameList);
userName.clear();
hostName.clear();
password.clear();
System.err.println("After remove domain name list ---> " + domainNameList);
System.err.println("After remove map ---> " + systemDetailsMap);
} else if (ce.getComponent().getId().equals("add")) {
System.err.println("Clicked add button...");
domain_name = domainName.getRawValue();
domainNameList.add(domain_name);
systemDetailsMap.put(domain_name, domain_name);
systemDetailsMap.put(domain_name + "_HOST_NAME", hostName.getValue());
systemDetailsMap.put(domain_name + "_USER_NAME", userName.getValue());
systemDetailsMap.put(domain_name + "_PASSWORD", password.getValue());
// domainName.clear();
domainName.add(domainNameList);
// domainName.reset();
System.err.println("After add domain name list ---> " + domainNameList);
System.err.println("After add map ---> " + systemDetailsMap);
} else if (ce.getComponent().getId().equals("new")) {
System.err.println("Clicked new button...");
userName.clear();
hostName.clear();
password.clear();
domainName.removeAllListeners();
domainName.removeAll();
domainName.clear();
domainName.setEmptyText("Add a new domain");
userName.setEmptyText("Add a new username");
hostName.setEmptyText("Add a new hostname");
password.setEmptyText("Add a new password");
domainName.addSelectionChangedListener(getReportSelectionListener());
}
}
};
private SelectionChangedListener<SimpleComboValue<String>> getReportSelectionListener(){
SelectionChangedListener<SimpleComboValue<String>> ReportListener = new SelectionChangedListener<SimpleComboValue<String>>() {
#Override
public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
SimpleComboValue<String> selectedValue = se.getSelectedItem();
String value = selectedValue.getValue();
System.err.println("Selected Value ---> " + selectedValue.getValue());
if (value != null && !value.equals("---New---") ){
userName.clear();
hostName.clear();
password.clear();
userName.setValue(systemDetailsMap.get(value + "_USER_NAME").toString());
hostName.setValue(systemDetailsMap.get(value + "_HOST_NAME").toString());
password.setValue(systemDetailsMap.get(value + "_PASSWORD").toString());
}
}
};
return ReportListener;
}
Please help me. Thanks in advance.
I am not using Ext-gwt just the standard ext-js, but I think I know what you need! You should define a display and value field.
Ext.create('Ext.form.ComboBox', {
store: xyz,
queryMode: 'local',
displayField: 'name',
valueField: 'id',
renderTo: Ext.getBody()
});
You just have to make sure, that the duplicated items are getting unique id. I think that if this is possible in ext-js it should also be possible in ext-gwt!

Categories

Resources