How To Validate a Devexpress Textbox inside an Devexpress Gridview in Javasacript - asp.net-mvc-4

i am not able to figure out why the focusout validation that uses the assigned regex is not working in the devex textbox. when i am using the textbox out of the grid it starts working as required. Kindly suggest the solution.
#Html.DevExpress().GridView(settings =>
{
settings.Columns.Add(column =>
{
column.FieldName = "InYear";
column.Caption = "In Year";
column.Width = 100;
column.ColumnType = MVCxGridViewColumnType.TextBox;
column.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending; // Default
column.SortIndex = 1;
column.CellStyle.HorizontalAlign = HorizontalAlign.Left;
var txtProperties = column.PropertiesEdit as TextBoxProperties;
txtProperties.Width = Unit.Percentage(100);
txtProperties.MaxLength = 4;
txtProperties.DisplayFormatInEditMode = true;
txtProperties.ValidationSettings.RequiredField.IsRequired = true;
txtProperties.ValidationSettings.ValidateOnLeave = true;
txtProperties.ValidationSettings.RegularExpression.ValidationExpression = #"\d{4}";
txtProperties.ValidationSettings.RegularExpression.ErrorText = "Expected format is: YYYY";
txtProperties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, e, '{0}', {1}); }}", "InYear", "0");
column.SetDataItemTemplateContent(c =>
{
if (!(bool)DataBinder.Eval(c.DataItem, "ReadOnly"))
{
Html.DevExpress().TextBox(txtSettings =>
{
txtSettings.Name = "txtInYear_" + c.KeyValue.ToString();
txtSettings.Width = Unit.Percentage(100);
txtSettings.Properties.MaxLength = 4;
txtSettings.Properties.DisplayFormatInEditMode = true;
txtSettings.Properties.ValidationSettings.ValidateOnLeave = true;
txtSettings.Properties.ValidationSettings.ValidationGroup = c.KeyValue.ToString();
txtSettings.Properties.ValidationSettings.RegularExpression.ValidationExpression = #"[0-9]{4}";
txtSettings.Properties.ValidationSettings.RegularExpression.ErrorText = "Expected format is: YYYY";
txtSettings.Properties.ClientSideEvents.ValueChanged = String.Format("function (s, e) {{ OnValueChanged(s, e, '{0}', {1}); }}", c.Column.FieldName, c.KeyValue);
}).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName)).Render();
}
else
Html.DevExpress().Label(lblSettings =>
{
lblSettings.Name = "lblInYear_" + c.KeyValue.ToString();
lblSettings.Width = Unit.Percentage(100);
}).Bind(DataBinder.Eval(c.DataItem, c.Column.FieldName).ToString()).Render();
});
});
}).Bind(Model).GetHtml()
EDIT : I am using a button out of the gridview to trigger the update command. How can i trigger only validate event of the EditRow. Please view attached image.
Thanks in advance

When do you need to validate the TextBox? In browser mode or when editing? Currently your TextBox is required when you edit a row. Try to set the IsRequired property for your TextBox in the template as well.
txtSettings.Properties.ValidationSettings.RequiredField.IsRequired = true;
It should work.

Go through this thread - MVC GridView - Client validation in default EditForm.
In case if you are working with ajax form then i suggest you use
built-in validation instead:GridView - How to use Microsoft
validation with an AJAX form to validate the Model properties on the
client side.
More References:
GridView - How to enable the client-side validation in the Edit Form
How to correctly enable Model, Unobtrusive or jQuery Client validation
Client Validation in MVC3 with Gridview Template Form

After a long struggle i got the following answer :
Assign a validation group property to the nested controls as below
txtSettings.Properties.ValidationSettings.ValidationGroup = c.KeyValue.ToString();
Iterate through the keyvalues on client side and call the devexpress validate function ASPxClientEdit.ValidateEditorsInContainer as following, i represent validation group name
var isValid =!ASPxClientEdit.ValidateEditorsInContainer(GridName.GetMainElement(), i)
My approach might not be the best but it helped me a lot, i think this would also be helpful for others having the same issue.
Thanks.....

Related

Codeigniter 4 - WHERE clause in Model

It's me again, Van.
Hi everyone,
I hope you're doing well!
I am doing a tutorial on a chat application using Codeigniter 4 with Ajax.
Everything worked fine until I applied the following code in the Model below
public function load_chat_data($sender_id,$receiver_id) {
// $where = ['sender_id' => $sender_id, 'receiver_id' => $receiver_id];
$where1 = "sender_id = $sender_id OR sender_id = $receiver_id";
$where2 = "receiver_id = $receiver_id OR receiver_id = $sender_id";
$builder = $this->db->table('chat_messages');
// $builder->where($where);
$builder->where($where1);
$builder->where($where2);
$builder->orderBy('chat_messages_id','ASC');
$results = $builder->get();
$rows = $results->getResultArray();
if($rows > 0)
{
return $rows;
}
else
{
return false;
}
}
The lines that I commented worked well before they were commented but it was not enough data I wanted to get so I tried to get both data of sender and receiver to display on the view by adding more code. However, when I tried $where1 and $where2 for the WHERE clauses, it didn't work. I think it must be the syntax error. Please correct my codes or any ideas on how the codes work with the same meaning supposed.
Thank you so much!!!
I tried as below, but it still didn't work.
$where1 = "sender_id={$sender_id} OR sender_id={$receiver_id}";
$where2 = "receiver_id={$receiver_id} OR receiver_id={$sender_id}";
Also, I tried:
$where1 = "'sender_id'=$sender_id OR 'sender_id'=$receiver_id";
$where2 = "'receiver_id'=$receiver_id OR 'receiver_id'=$sender_id";
I think you are trying to receive the messages of the conversation between two people. Can you try the following code for this?
$builder->groupStart(); // or $builder->orGroupStart();
$builder->where('sender_id', $sender_id);
$builder->where('receiver_id', $receiver_id);
$builder->groupEnd();
$builder->orGroupStart();
$builder->where('sender_id', $receiver_id);
$builder->where('receiver_id', $sender_id);
$builder->groupEnd();

Eventbrite API date range parameter for organizer_list_events

I need a way to search via the eventbrite api past events, by organizer, that are private, but I also need to be able to limit the date range. I have not found a viable solution for this search. I assume the organizer_list_events api would be the preferred method, but the request paramaters don't seem to allow for the date range, and I am getting FAR too many returns.
I'm having some similar issues I posted a question to get a response about parsing the timezone, here's the code I'm using to get the dates though and exclude any events before today (unfortunately like you said I'm still getting everything sent to me and paring things out client side)
Note this is an AngularJS control but the code is just using the EventBrite javascript API.
function EventCtrl($http, $scope)
{
$scope.events=[];
$scope.noEventsDisplay = "Loading events...";
Eventbrite({'app_key': "EVC36F6EQZZ4M5DL6S"}, function(eb){
// define a few parameters to pass to the API
// Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
//3877641809
var options = {
'id' : "3588304527",
};
// provide a callback to display the response data:
eb.organizer_list_events( options, function( response ){
validEvents = [];
var now = new Date().getTime();
for(var i = 0; i<response.events.length; i++)
{
var sd = response.events[i].event.start_date;
var ed = response.events[i].event.end_date;
var parsedSD = sd.split(/[:-\s]/);
var parsedED = ed.split(/[:-\s]/);
var startDate = new Date(parsedSD[0], parsedSD[1]-1, parsedSD[2], parsedSD[3], parsedSD[4], parsedSD[5]);
var endDate = new Date(parsedED[0], parsedED[1]-1, parsedED[2], parsedED[3], parsedED[4], parsedED[5]);
if(endDate.getTime()<now)
continue;
response.events[i].event.formattedDate = date.toDateString();
validEvents.push(response.events[i])
}
if(validEvents.length == 0)
{
$scope.$apply(function(scope){scope.noEventsDisplay = "No upcoming events to display, please check back soon.";});
}
else
{
$scope.$apply(function(scope){scope.noEventsDisplay = "";});
}
$scope.$apply(function(scope){scope.events = validEvents;});
//$('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
});
});
}

Use of SPStatefulLongOperation

Can someone give me an example of the use of SPStatefulLongOperation? It's very poorly documented.
Here's an example of code I've just used. It applies a ThmxTheme (selectedTheme) to all SPWebs in an SPSite (site).
SPStatefulLongOperation.Begin(
"Applying theme to sites.",
"<span id='trailingSpan'></span>",
(op) =>
{
op.Run((opState) =>
{
for (int i = 0; i < site.AllWebs.Count; i++)
{
// Update status.
opState.Status = String.Format(
"<script type='text/javascript'>document.all.item('trailingSpan').innerText = '{0} ({1} of {2})';</script>",
site.AllWebs[i].Title,
i + 1,
site.AllWebs.Count);
// Set the theme.
selectedTheme.ApplyTo(site.AllWebs[i], true);
}
});
op.End(System.Web.HttpContext.Current.Request.UrlReferrer.ToString());
});
Note that the current value of opState.State is appended to the client's HTML (via HttpContext.Current.Response.Write and .Flush) every second. Thus you don't want to send any status message directly; you want to send some JavaScript that will update an existing status element on the page. (Here, the trailingSpan element.)

Adobe 9 Check box required field

I've created reports in Adboe that have checkobxes and set then to required fields.
But when i click the submit button all fields but the check boxes are validated.
I.e
If i dont complete the required textbox field the report will not submit, but when i do and the required checkbox fields are not checked it still submits.
This only appears to be happening on Adobe 9
Any ideas?
Thanks
Sp
Here is a link to a test page
http://www.mediafire.com/?mnkmmlime2f
If you fill the text box with anything it will submit regardless of the check box status (which is also a required field)
I have figured it out.
Adobe Reader checkbox allows has a value (default "false") so when the form validates it sees the checkbox as having a value.
I've had to write some java to stop the form submitting if the checkbox has a null/False/false value
This works like a dream
Thanks for trying to help wit hthis post all
var f;
var Valid = "1";
for (var i = 0; i < this.numFields; i++)
{
f = this.getField(this.getNthFieldName(i));
if (f.type == 'checkbox')
{
if(f.required == true)
{
if(f.value == "false" || f.value == "False" || f.value == "null")
{
Valid = "0";
}
}
}
};
if(Valid == "1")
{
this.submitForm('');
}
else
{
app.alert("Please complete all required fields");
}

How to get output of a webpage in ActionScript 2

For Actionscript 2.0
Let's say this page
www.example.com/mypage
returns some html that I want to parse in Actionscript.
How do i call this page from Actionscript while getting back the response in a string variable?
use LoadVars():
var lv = new LoadVars();
//if you want to pass some variables, then:
lv.var1 = "BUTTON";
lv.var2 = "1";
lv.sendAndLoad("http://www.example.com/mypage.html", lv, "POST");
lv.onLoad = loadedDotNetVars;
function loadedDotNetVars(success)
{
if(success)
{
// operation was a success
trace(lv.varnameGotFromPage)
}
else
{
// operation failed
}
}
//if you dont want to send data, just get from it, then use just lv.Load(...) instead of sendAndLoad(...)
I understand. Use this code then:
docXML = new XML(msg);
XMLDrop = docXML.childNodes;
XMLSubDrop = XMLDrop[0].childNodes;
_root.rem_x = (parseInt(XMLSubDrop[0].firstChild));
_root.rem_y = (parseInt(XMLSubDrop[1].firstChild));
_root.rem_name = (XMLSubDrop[2].firstChild);
var htmlFetcher:LoadVars = new LoadVars();
htmlFetcher.onData = function(thedata) {
trace(thedata); //thedata is the html code
};
Use:
htmlFetcher.load("http://www.example.com/mypage");
to call.
I suppose you could use:
page = getURL("www.example.com/mypage.html");
And it would load the page contents on the page variable.