Angular js Select reset - angularjs

I have a angular select drop down with ng-options and ng-model and two input text boxes.when i select last option in drop down text boxes are enabled which are disabled by default.If i am selecting last value in drop down text boxes are enabling and on reload of page i made condition to select a option with empty value.And when i select last option again still text boxes are in disabled mode
Rangeslicer += "<div id='Rangeslicer"+id+"'>"
Rangeslicer += " <select class='selectpicker' id='rangepicker" + id + "' data-ng-change='RangeSelection(" + '"' + id + '"' + ")' ng-options='dayNames as dayNames.dayName for dayNames in RangeSelector' style='border-radius:5px;height:25px;outline:0px;text-align:center'>"
// Rangeslicer += " <select id='rangepicker" + id + "' ng-options='dayNames.id as dayNames.dayName for dayNames in RangeSelector' style='border-radius:20px;height:25px;outline:0px;text-align:center' ng-model='rangepicker" + id + "'>"
Rangeslicer += " <option value=''>Select Date Range</option>"
Rangeslicer += "</select> <br/>"
Rangeslicer += " <div id='custominput' style='margin-top:4%'><input type='text' class='daterangecustom" + id + " datecustom' id='customstart" + id + "' disabled ng-model='customstart' style='height:25px;border-radius:5px;width:35%;margin-right:10%;margin-left:3%;text-align:center;outline:0px'/><input type='text' class='daterangecustom" + id + " datecustom' id='customend" + id + "' disabled ng-model='customend' ng-mouseleave='compareDates(" + '"' + id + '"' + ")' style='border-radius:5px;width:35%;height:25px;text-align:center;outline:0px'/></br><p id='errormessage" + id + "' style='display:none;margin-bottom:0px'>Please ensure that the End Date is greater than or equal to the Start Date.</p></div></div>"
//$compile($('#Rangeslicer').empty())($scope);
// $compile($("#divChk" + id).empty())($scope);
$compile($("#main" + id).append(Rangeslicer))($scope);
$('select.selectpicker option:first').prop('selected', true);
Actually when option is changed to last value textboxes should enable

Try using ng-disabled="lastSelected()" on your inputs, where lastSelected is a function that checks if the ng-model value on your select is the empty item.

Related

I tried to automate json views in snowflake. But it displays error in the regex

I tried this approach and it is displaying an error that the regex has a missing statement. The approach that I am trying is from the Automating Snowflake’s Semi-Structured JSON Data Handling
CREATE OR REPLACE PROCEDURE create_view_over_json (TABLE_NAME varchar, COL_NAME varchar, VIEW_NAME varchar, COLUMN_CASE varchar, COLUMN_TYPE varchar)
RETURNS VARCHAR
LANGUAGE javascript
AS
$$
var alias_dbl_quote = "";
var path_name = "regexp_replace(regexp_replace(f.path,'\\[(.+)\\]'),'(\\w+)','"\\1"')" // This generates paths with levels enclosed by double quotes (ex: "path"."to"."element"). It also strips any bracket-enclosed array element references (like "[0]")
var attribute_type = "DECODE (substr(typeof(f.value),1,1),'A','ARRAY','B','BOOLEAN','I','FLOAT','D','FLOAT','STRING')"; // This generates column datatypes of ARRAY, BOOLEAN, FLOAT, and STRING only
var alias_name = "REGEXP_REPLACE(REGEXP_REPLACE(f.path, '\\[(.+)\\]'),'[^a-zA-Z0-9]','_')" ; // This generates column aliases based on the path
var table_list = TABLE_NAME;
var col_list = "";
var array_num = 0;
if (COLUMN_CASE.toUpperCase().charAt(0) == 'M') {
alias_dbl_quote = """; } // COLUMN_CASE parameter is set to 'match col case' so add double quotes around view column alias name
if (COLUMN_TYPE.toUpperCase().charAt(0) == 'S') {
attribute_type = "DECODE (typeof(f.value),'ARRAY','ARRAY','STRING')"; } // COLUMN_TYPE parameter is set to 'string datatypes' so typecast to STRING instead of value returned by TYPEPOF function
// Build a query that returns a list of elements which will be used to build the column list for the CREATE VIEW statement
var element_query = "SELECT DISTINCT n" +
path_name + " AS path_name, n" +
attribute_type + " AS attribute_type, n" +
alias_name + " AS alias_name n" +
"FROM n" +
TABLE_NAME + ", n" +
"LATERAL FLATTEN(" + COL_NAME + ", RECURSIVE=>true) f n" +
"WHERE TYPEOF(f.value) != 'OBJECT' n" +
"AND NOT contains(f.path,'[') "; // This prevents traversal down into arrays
// Run the query...
var element_stmt = snowflake.createStatement({sqlText:element_query});
var element_res = element_stmt.execute();
// ...And loop through the list that was returned
while (element_res.next()) {
if (element_res.getColumnValue(2) != 'ARRAY') {
if (col_list != "") {
col_list += ", n";}
col_list += COL_NAME + ":" + element_res.getColumnValue(1); // Start with the element path name
col_list += "::" + element_res.getColumnValue(2); // Add the datatype
col_list += " as " + alias_dbl_quote + element_res.getColumnValue(3) + alias_dbl_quote; // And finally the element alias
}
// Array elements get handled in the following section:
else {
array_num++;
var simple_array_col_list = "";
var object_array_col_list = "";
// Build a query that returns the elements in the current array
var array_query = "SELECT DISTINCT n"+
path_name + " AS path_name, n" +
attribute_type + " AS attribute_type, n" +
alias_name + " AS attribute_name, n" +
"f.index n" +
"FROM n" +
TABLE_NAME + ", n" +
"LATERAL FLATTEN(" + COL_NAME + ":" + element_res.getColumnValue(1) + ", RECURSIVE=>true) f n" +
"WHERE REGEXP_REPLACE(f.path, '.+(\\w+\\[.+\\]).+', 'SubArrayEle') != 'SubArrayEle' "; // This prevents return of elements of nested arrays (the entire array will be returned in this case)
while (array_res.next()) {
if (array_res.getColumnValue(1).substring(1) == "") { // The element path name is empty, so this is a simple array element
if (simple_array_col_list != "") {
simple_array_col_list += ", n";}
simple_array_col_list += COL_NAME + ":" + element_res.getColumnValue(1); // Start with the element path name
simple_array_col_list += "[" + array_res.getColumnValue(4) + "]"; // Add the array index
simple_array_col_list += "::" + array_res.getColumnValue(2); // Add the datatype
simple_array_col_list += " as " + alias_dbl_quote + element_res.getColumnValue(3) + "_" + array_res.getColumnValue(4) + alias_dbl_quote; // And finally the element alias - Note that the array alias is added as a prefix to ensure uniqueness
}
else { // This is an object array element
if (object_array_col_list != "") {
object_array_col_list += ", n";}
object_array_col_list += "a" + array_num + ".value:" + array_res.getColumnValue(1).substring(1); // Start with the element name (minus the leading '.' character)
object_array_col_list += "::" + array_res.getColumnValue(2); // Add the datatype
object_array_col_list += " as " + alias_dbl_quote + element_res.getColumnValue(3) + array_res.getColumnValue(3) + alias_dbl_quote; // And finally the element alias - Note that the array alias is added as a prefix to ensure uniqueness
}
}
// If no object array elements were found then add the simple array elements to the
// column list...
if (object_array_col_list == "") {
if (col_list != "") {
col_list += ", n";}
col_list += simple_array_col_list;
}
// ...otherwise, add the object array elements to the column list along with a
// LATERAL FLATTEN clause that references the current array to the table list
else {
if (col_list != "") {
col_list += ", n";}
col_list += object_array_col_list;
table_list += ",n LATERAL FLATTEN(" + COL_NAME + ":" + element_res.getColumnValue(1) + ") a" + array_num;
}
}
}
// Now build the CREATE VIEW statement
var view_ddl = "CREATE OR REPLACE VIEW " + VIEW_NAME + " AS n" +
"SELECT n" + col_list + "n" +
"FROM " + table_list;
// Now run the CREATE VIEW statement
var view_stmt = snowflake.createStatement({sqlText:view_ddl});
var view_res = view_stmt.execute();
return view_res.next();
$$;
I tried this approach but it is displaying an error that regex has the [link I followed ][1]error.
REGEX ERROR*
[1]: https://www.snowflake.com/blog/automating-snowflakes-semi-structured-json-data-handling-part-2/#
I am getting this error:
JavaScript compilation error: Uncaught SyntaxError: Invalid or unexpected token
in CREATE_VIEW_OVER_JSON at ' var path_name = "regexp_replace(regexp_replace(f.path,'\[(.+)\]'),'(\\w+)','"\\1"')" ;'
position 82
Your error can be produced with just the first two line of the SP because you have you quotes incorrectly escaped/paired for the task:
CREATE OR REPLACE PROCEDURE create_view_over_json (TABLE_NAME varchar, COL_NAME varchar, VIEW_NAME varchar, COLUMN_CASE varchar, COLUMN_TYPE varchar)
RETURNS VARCHAR
LANGUAGE javascript
AS
$$
var alias_dbl_quote = "";
var path_name = "regexp_replace(regexp_replace(f.path,'\\[(.+)\\]'),'(\\w+)','"\\1"')" // This generates paths with levels enclosed by double quotes
$$;
call create_view_over_json(null,null,null,null,null);
gives:
100131 (P0000): JavaScript compilation error: Uncaught SyntaxError: Invalid or unexpected token in CREATE_VIEW_OVER_JSON at 'var path_name = "regexp_replace(regexp_replace(f.path,'\[(.+)\]'),'(\w+)','"\1"')" // This generates paths with levels enclosed by double quotes ' position 79
In SQL and in Javascript you cannot put the Quote you are using to wrap are "string" in the string without escaping. In SQL you can use $$ or ' so you have used $$ for the stored procedure body. Where inside the JavaScript you can use ', ", `
Thus in this line you have used double quoutes, which means you can embed the single quotes, but those doubles you have in the string terminate the string..
"regexp_replace(regexp_replace(f.path,'\\[(.+)\\]'),'(\\w+)','"\\1"')"
^ ^
Thus given you need to use both single and double you should wrap the string in back qoutes `
var path_name = `regexp_replace(regexp_replace(f.path,'\\[(.+)\\]'),'(\\w+)','"\\1"')`;

How to add double quotes in data binding value in angularjs directive?

I am using angularjs directive and I want to add double quotes for a value which is get through data binding in angularjs template.
my code is,
template = '<div>'+
'<a>'+'User name is ' + user.name + '</a>'+
'</div>'
I need the output as given below
User name is "davit"
How to add double quotes for the name davit?
just add the double quotes before and after single quotes like this
'<a>'+'User name is "' + user.name + '"</a>'+
Try this:-
template = '<div>'+ '<a>'+'User name is "' + user.name + '"</a>'+ '</div>'

How to set AngularJS drop down default value

my HTML code for drop down like follow:
<select ng-model="selected_value"
ng-options="(x.version + ' ' + ' : ' + x.status) for x in allData"></select>
my Angular code like follow :
data comes from a rest service
$http.get(......).success(function (data, status){
$scope.allData = data;
$scope.selected_value = $scope.allData[0].version + " : " + $scope.allData[0].status;
});
Data comes to the drop down. but initially drop down does not display the value. It shows if only select the value. Can someone help on this issue.
Add ng-selected="selected_value" to the select element.
An example of what you are trying to achieve can be found in the ngSelected documentation.

Create a dynamic SOQL Query using variable objects

I'm trying to execute a dynamic soql query using variable objects.
In my visualforce page i have tow apex:selectlist, the first one contains a list of objects, when i select one object from this list, i refresh the second list to display selected object's fields.
The apex:inputText contains text to search in selected field.
visual force code:
<apex:selectList id="listObjects" value="{!selectedObject}" size="1">
<apex:selectOptions value="{!allObjetcs}"></apex:selectOptions>
</apex:SelectList>
<apex:selectList id="listFields" value="{!selectedField}" size="1">
<apex:selectOptions value="{!allFields}"></apex:selectOptions>
</apex:SelectList>
<label>Text to search : </label><apex:inputText id="textResearch" value="{!textResearch}" />
<button id="searchButton" type="button">{!$Label.SEARCH}</button>
apex code :
public void search() {
result = new List<SearchWrapper>();
System.debug('>>>>>> ALK - in search ');
String query = 'Select Id, ' + selectedField + ' from ' + selectedObject + ' where ' + selectedField + ' like \'%' + textResearch + '\'%';
System.debug('>>>>>> ALK - Query : ' + query);
List<sObject> = (sObject) Database.query(query);
}
Please how can i cast Database.query(query) and how can i execute this dynamic query.
Thanks for all.
if you are using a local variable in your query you must put ':' before that. like this:
String value = 'test';
List<something> result = [select id from something where name = :value];
Try below code. If field list if multiselect, you might have to iterate over the selectedField variable and form a string of field names separated by comma.
String query = 'select '+String.valueOf(selectedField)+' From '+selectedObject+' WHERE Name = \'' + textResearch+'\'';
List<sObject> recordList = Database.query(query);
public void search() {
result = new List<SearchWrapper>();
String query = 'Select ' + selectedField + ' from ' + selectedObject + ' where ' + selectedField + ' like \'%' + textResearch + '%\'';
System.debug('>>>>>> Query : ' + query);
List<sObject> l = Database.query(query);
}

What's the most efficient way to search text of any data type in EF6?

I try to dynamically create some LINQ query for searching data in all columns.
Currently, I use the following code to build dynamic LINQ query. However, it's quite buggy when deals with complex column.
var type = property[col.ToLower()].PropertyType;
var isNullableType = type.IsGenericType && type.GetGenericTypeDefinition() == typeof (Nullable<>);
if (type.IsValueType && !isNullableType)
{
filter += col + ".ToString().ToLower().Contains(#" + i + ".ToLower())";
}
else if (isNullableType)
{
filter += col + ".HasValue ? " + col + ".Value.ToString().ToLower().Contains(#" + i + ".ToLower())" + " : false";
}
else
{
filter += "(" + col + " != null ? " + col + " : \"\").ToString().ToLower().Contains(#" + i + ".ToLower())";
}
Do you have any idea to simplify my above code? I'm OK if your suggestion is work only for SQL Server 2008 or later.
Note:
Column data can be any type like integer, string, object, enum and it can be null.

Resources