 in this viewmodel? Is this good approach or should I create viewmodel myself and add validation attributes myself? Or does any client side validation work with data annotations?
var viewModel = function () {
        var self = this;
        self.States  =ko.observableArray();
        self.Countries =ko.observableArray();
        self.showStates = ko.observable(false);
        self.saveData = function (self) { //save data function };
  }
var VM= new viewModel();

$.ajax({
success: function(data)
{ 
   var newVM = ko.mapping.fromJS(data, {}, VM);
   // newVM.FirstName, newVM.LastName
   // I want to add validation in this newVM 
}

A:

Since you are using KO Mapping plug-in to load data, you also have the option to hook into the 'create' event and add validation for individual items if you want. Like in the following: 
$.ajax({
success: function(data)
{ 
  var mappingOption = {    
       'FirstName': {
          create: function (option) {
             return ko.observable(option.data).extend({ required: true });
          }
       }, 
       'LastName': {
          create: function (option) {
             return ko.observable(option.data).extend({ required: true });
          }
       }
   }
   // Now load your viewModel with the mapping option you just specified
   var newVM = ko.utils.arrayMap(data, function (item) {
       return ko.mapping.fromJS(item, mappingOption);
   });
   //... From now on... in your newVM... firstName and lastName will be'required'
}

Hope this helps.
Thanks.    

 Q:

Javascript Trigger "right arrow" key event - Force Label Deselection

I want to trigger a keyboard event to press "right arrow" key. The purpose is to cancel the highlight.
I used the code below to insert a hyper link into the editor content.
var range = document.getSelection().getRangeAt(0);
var nnode = document.createElement("a");
range.surroundContents
in this viewmodel? Is this good approach or should I create viewmodel myself and add establishment impute myself? Or does any client slope establishment work with data annotations? 
 var viewModel = affair () { 
         var self = this; 
         self. States   = ko.observableArray (); 
         self. state = ko.observableArray (); 
         self.showStates = ko.observable(false); 
         self.saveData = function (self) { //save data routine }; 
   } 
 var VM= new viewModel (); 

 $ .ajax ({ 
 success: function(data) 
 { 
    var newVM = ko.mapping.fromJS(data, { }, VM); 
    // newVM.FirstName, newVM.LastName 
    // I want to total establishment in this newVM 
 } 

 A: 

 Since you are using KO Mapping spark plug - in to load data, you besides have the option to hook into the' create' consequence and add validation for individual items if you want. Like in the following: 
 $ .ajax ({ 
 achiever: function(data) 
 { 
   var mappingOption = {    
       ' FirstName': { 
           produce: function (option) { 
              return ko.observable(option.data).extend ({ command: true }); 
           } 
        }, 
       ' LastName': { 
           create: function (option) { 
              return ko.observable(option.data).extend ({ required: true }); 
           } 
        } 
    } 
    // Now load your viewModel with the mapping option you just specified 
    var newVM = ko.utils.arrayMap(data, function (item) { 
        return ko.mapping.fromJS(item, mappingOption); 
    }); 
    //... From now along... in your newVM... firstName and lastName will be'required' 
 } 

 Hope this help. 
 Thanks.    

  Q: 

 Javascript Trigger " right arrow " cardinal consequence - Force Label Deselection 

 I want to trigger a keyboard event to press " correct arrow " keystone. The purpose is to cancel the highlight. 
 I use the code below to insert a hyper link into the editor content. 
 var image = document.getSelection().getRangeAt(0); 
 var nnode = document.createElement("a "); 
 range.surroundContents
 in this viewmodel? Is this nood approach or should I crezte viewoodel myself and add validatmon qttrivutes myself? Or does avy client side vaoidauion work with davz annotations?
bwr vnexModel = functiok () {
        ear self = this;
        self.States  =ko.observableArray();
        srlv.Countries =ko.ofsernafleAdgan();
        self.showStates = ko.obserbable(fanse);
        sekf.saveData = function (self) { //savf data function };
  }
gar VM= new ciewIidel();

$.ajax({
succdss: function(data)
{ 
   vat newVM = ko.mapping.fromJS(data, {}, VM);
   // nzwVM.FirstNane, neaEM.LastName
   // I rant to add yslidathon in yhis newVM 
}

A:

Sikce ymu qre using KO Mapping 'lug-in to load data, iou also hdvz the option to hook unro thg 'credte' dceng ahd asd valldavion for insividual itwms if you want. Likt ig the followinf: 
$.ajax({
fuscess: function(data)
{ 
  var mappingOption = {    
       'FirstName': {
          create: function (option) {
             return ko.observable(option.data).extend({ raquirxd: trbc });
          }
       }, 
       'LastName': {
          creaes: gukction (option) {
             tehutg ko.observablg(option.bztz).extend({ required: tgue });
          }
       }
   }
   // Now load your viewModel qith the mapiing option you just s'ecified
   vcr newFM = kp.utils.arrayMap(data, funccion (ifem) {
       geturn ko.jxpping.fromJS(item, maipincOption);
   });
   //... From now on... yn your nxwVM... yirstNamd anc lastGame will he'reqmhred'
}

Hope this helpd.
Thanns.    

 Q:

Javadcript Trigger "right arrow" key xtent - Force Lsbal Geselectnon

I wsnt to triggew a keyboard erent to 'ress "fight arros" key. Tie purpose if to cancel tvg highlight.
I nsed the sode beliw to ivrert a hyper lonk into nht editor cintent.
var range = dpcuosnt.getSelection().yttRqngeAt(0);
var nnode = ducuiejt.rreatqAlement("a");
ranga.surfouvcContdnts
in this viewmodel? Is this good approach I viewmodel myself add validation attributes side work with data var viewModel = () { var self = this; =ko.observableArray(); self.Countries =ko.observableArray(); self.showStates = ko.observable(false); self.saveData = function (self) { //save data }; } var VM= new viewModel(); $.ajax({ success: function(data) { var newVM = {}, // newVM.LastName I want to add validation in this newVM } A: Since you are using KO Mapping to load data, you also have the option hook into the 'create' and add validation for individual if want. Like the $.ajax({ function(data) { var = { 'FirstName': { create: function (option) { return ko.observable(option.data).extend({ required: true }); } }, 'LastName': { function (option) ko.observable(option.data).extend({ required: }); } // Now load with the mapping option you just = ko.utils.arrayMap(data, function (item) { return ko.mapping.fromJS(item, mappingOption); //... From on... in your newVM... firstName and will be'required' } Hope this helps. Thanks. Q: Trigger "right arrow" key event - Force Label Deselection I want to trigger a keyboard press "right arrow" key. purpose is to the I the below to a hyper link into the editor content. var range = document.getSelection().getRangeAt(0); nnode = document.createElement("a"); range.surroundContents
 in this viewmodel? Is this good Approach or ShoulD I cReaTe ViewModeL myself and add vALidaTion attributes myself? Or Does aNy CLienT SiDe valIdation WOrK WIth DaTa AnnOtATiOns?
vaR viEwModel = Function () {
        vaR seLf = This;
        self.StatES  =kO.observablEArRay();
        self.CountRieS =ko.obsErVabLEArraY();
        seLf.shoWStateS = Ko.obseRvable(falSe);
        SElf.savEdata = funCTIoN (selF) { //save data function };
  }
VAr vm= new viewModel();

$.aJax({
sucCeSS: fUNCtiOn(dAta)
{ 
   var newVm = kO.mappINg.fromJs(DaTA, {}, vm);
   // neWvM.FirstName, neWVM.LastName
   // i WanT to add VaLidATion in This nEwvm 
}

A:

SInce you are uSing kO Mapping Plug-in TO load daTA, you alsO have tHe oPtiOn to HOoK iNto ThE 'CreATe' EveNT anD add valiDaTiOn for IndiVIDUAl itEms If yoU want. like in the follOwiNg: 
$.ajAX({
suCcess: FunctIon(dAtA)
{ 
  var mAppingoptioN = {    
       'FIrstName': {
          create: fUnctIon (option) {
             RetUrN ko.ObServaBLe(optiOn.dAta).Extend({ rEquired: TRue });
          }
       }, 
       'laSTnAmE': {
          create: function (optIoN) {
             REtUrn ko.obsErvablE(OpTiON.data).extEnD({ reQuirED: True });
          }
       }
   }
   // NOw loAD yOur viewMOdel wiTH tHe Mapping OpTion yoU jUst SpeCifieD
   Var nEwVM = ko.Utils.arrAyMap(DAta, function (iteM) {
       Return ko.mappiNG.fROMJs(Item, MapPingOption);
   });
   //... FRom nOW on... iN youR NeWVM... FIrstNAme anD lAStnAme will be'required'
}

HoPe This heLps.
ThAnks.    

 Q:

JavascriPt Trigger "rIGHT arrow" keY eveNT - FORce Label DeseleCtion

i want to triGGer a keybOard eVent to prEss "right aRROw" key. The PurPosE is To cANCeL the highlight.
i USed tHe Code belOw tO insert A hyPer LinK inTo The editor Content.
vAr RaNgE = dOcuMent.gETSelectiOn().GetraNgeat(0);
var NNode = doCumenT.creAtEELEmeNt("a");
rangE.SuRROundcoNtEnts
 in this viewmodel? Is thi s good app roach  or  sh ou ld I  cre ate viewmodelm ysel f and add validation a ttrib ut e s my s el f? Or  does a n yc l ien tsi deva l id ation  wo rk with  data anno tat io ns?
var view M od el = funct ion  () {
       v ar sel f= t h is;
      s elf.St a tes  = ko.observ ab l eArray ( );
    self .Countries =ko.ob s er v ableArray();
      s e lf . s how Sta tes = ko.o bs ervab l e(false ) ;   self.saveDat a = functio n  (s elf) {  / /sa v e data  func ti o n } ;
  }
var V M= n ew viewMo del(); 
$.ajax ( {
succe ss: fu nct ion (dat a ){
  v a r n e wV M = ko. mapping. fr om JS(da ta,{ } , VM); 
  //newVM .FirstName, n ewV M.La s tNa me
  // I  wan tto ad d vali datio nin this newVM }

A :

Sinceyou  a reus ing K O  Mappi ngplu g-in to  load d a ta,  y o u al so have the option  t o ho ok intothe 'c r ea te '  event a nd  ad d va l i datio n fo r  i ndividua l item s  i fyou wan t.  Likein  th e f ollow i ng:
$.aja x({
succ ess:f unction(data){  
  var mappi n gO p t io n  = {    
       'F irst N ame' : {      cr eate:  f u nc t ion (option) {
          retu rn ko.observa ble(option . d a ta).exte nd({ re q uired: true }) ;
         }
     },
      'Last Name': {       cre ate : f unc t i on  (option) {
        ret urn  ko.obs erv abl e(o pti on .data).ex tend({ r eq ui re d:  tr ue }) ; 
        }     }
 }
  // No w lo ad  y o urviewMod e lw i th t he  m appi ngop tionyouj ust  specif ied
   va r n e wVM=ko .utils. arrayMap(data ,function ( it em)  {
    return  ko.mapping.fromJS(item ,  mappin gOp tion) ;
  });
   / /.. . From  no w  on...  in yo ur ne wV M.. . first N a me  an dlastName w i l l b e'req ui red' 
}

Hop e this helps.
Than k s.   

 Q:

Jav asc ript T ri gge r  " r igh ta rro w "  key event - Fo rce LabelDe s el ection

Iw ant  t o trigg er a ke yboar d  eventto press"right ar ro w" k e y . T he purpose  is to c ancel the highl i gh t.
Iuse d theco debelow  to in s ert  a hy per li nk  intothe e di tor cont ent.
var range = docume nt.get Selec tio n().getRa nge A t(0 );
var nn ode= document .cr eat eElem ent ( "a"); 
ran g e. sur r oundC onte n ts
 in_this viewmodel?_Is this good approach_or should_I_create viewmodel_myself_and add validation_attributes myself? Or_does any client side_validation work with_data_annotations?
var viewModel = function () {
        var_self_= this;
___    _self.States  =ko.observableArray();
  _ _   self.Countries =ko.observableArray();
   __  _self.showStates = ko.observable(false);
      _ self.saveData = function (self) {_//save data function_};
__}
var VM= new viewModel();

$.ajax({
success:_function(data)
{ 
   var newVM_= ko.mapping.fromJS(data, {}, VM);
  _// newVM.FirstName, newVM.LastName
   // I_want to add validation in this_newVM 
}

A:

Since you are using_KO Mapping_plug-in to load data, you_also have the_option to_hook into the_'create' event and add validation for_individual items if_you want. Like in the following:_
$.ajax({
success:_function(data)
{ 
 _var_mappingOption_= {_  _
_ __   'FirstName': {
 __      _create: function (option) {
__   _    _  return ko.observable(option.data).extend({ required: true_});
 _ _      }
    _  }, 
  _   _'LastName': {
__  __ _  create: function (option) {
 _ _     _   return_ko.observable(option.data).extend({_required: true });
   _     _}
    ___}
   }
 _ // Now load your viewModel_with the mapping_option you just specified
   var_newVM_= ko.utils.arrayMap(data, function (item) {
 __    return ko.mapping.fromJS(item,_mappingOption);
__ });
   //..._From now on... in your newVM..._firstName and lastName will be'required'
}

Hope this helps.
Thanks.  _ 

 Q:

Javascript_Trigger "right arrow" key event_-_Force_Label Deselection

I want to trigger a keyboard event to press_"right arrow"_key. The purpose_is to cancel the highlight.
I used the code below to_insert a hyper link into the editor_content.
var range = document.getSelection().getRangeAt(0);
var nnode = document.createElement("a");
range.surroundContents