当前位置: 首页>>代码示例>>PHP>>正文


PHP NumericField::setValue方法代码示例

本文整理汇总了PHP中NumericField::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP NumericField::setValue方法的具体用法?PHP NumericField::setValue怎么用?PHP NumericField::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NumericField的用法示例。


在下文中一共展示了NumericField::setValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setValue

 /**
  * @param mixed $val
  * @param array $data
  * @return $this
  */
 public function setValue($val, $data = array())
 {
     // convert to a number
     parent::setValue(str_replace('%', '', $val));
     $dataVal = $this->dataValue();
     // divide by 100 if needed and set again
     if (strpos($val, '%') !== false || $dataVal > 1 || $dataVal < -1) {
         $dataVal = (double) $dataVal / 100.0;
         parent::setValue($dataVal);
     }
     return $this;
 }
开发者ID:markguinn,项目名称:silverstripe-shop-extendedpricing,代码行数:17,代码来源:PercentageField.php

示例2: setValue

 public function setValue($val)
 {
     $this->value = $val;
     if (is_array($val)) {
         $this->fieldCurrency->setValue($val['Currency']);
         $this->fieldAmount->setValue($val['Amount']);
     } elseif ($val instanceof DBMoney) {
         $this->fieldCurrency->setValue($val->getCurrency());
         $this->fieldAmount->setValue($val->getAmount());
     }
     // @todo Format numbers according to current locale, incl.
     //  decimal and thousands signs, while respecting the stored
     //  precision in the database without truncating it during display
     //  and subsequent save operations
     return $this;
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:16,代码来源:MoneyField.php

示例3: checkInputValidation

 protected function checkInputValidation($locale, $tests)
 {
     i18n::set_locale($locale);
     $field = new NumericField('Number');
     $validator = new RequiredFields('Number');
     foreach ($tests as $input => $output) {
         // Both decimal and thousands B
         $field->setValue($input);
         if ($output === false) {
             $this->assertFalse($field->validate($validator), "Expect validation to fail for input {$input} in locale {$locale}");
             $this->assertEquals(0, $field->dataValue(), "Expect invalid value to be rewritten to 0 in locale {$locale}");
             // Even invalid values shouldn't be rewritten
             $this->assertEquals($this->clean($input), $field->Value(), "Expected input {$input} to be saved in the field in locale {$locale}");
         } else {
             $this->assertTrue($field->validate($validator), "Expect validation to succeed for {$input} in locale {$locale}");
             $this->assertEquals($output, $field->dataValue(), "Expect value {$input} to be mapped to {$output} in locale {$locale}");
         }
     }
 }
开发者ID:nickbooties,项目名称:silverstripe-framework,代码行数:19,代码来源:NumericFieldTest.php

示例4: testValidator

 public function testValidator()
 {
     i18n::set_locale('en_US');
     $field = new NumericField('Number');
     $field->setValue('12.00');
     $validator = new RequiredFields('Number');
     $this->assertTrue($field->validate($validator));
     $field->setValue('12,00');
     $this->assertFalse($field->validate($validator));
     $field->setValue('0');
     $this->assertTrue($field->validate($validator));
     $field->setValue(false);
     $this->assertFalse($field->validate($validator));
     i18n::set_locale('de_DE');
     $field->setValue('12,00');
     $validator = new RequiredFields();
     $this->assertTrue($field->validate($validator));
     $field->setValue('12.00');
     $this->assertFalse($field->validate($validator));
     $field->setValue(0);
     $this->assertRegExp("#<span[^>]+>\\s*0\\s*<\\/span>#", "" . $field->performReadonlyTransformation()->Field() . "");
 }
开发者ID:8secs,项目名称:cocina,代码行数:22,代码来源:NumericFieldTest.php

示例5: testValidator

 public function testValidator()
 {
     i18n::set_locale('en_US');
     $field = new NumericField('Number');
     $field->setValue('12.00');
     $validator = new RequiredFields('Number');
     $this->assertTrue($field->validate($validator));
     $field->setValue('12,00');
     $this->assertFalse($field->validate($validator));
     $field->setValue('0');
     $this->assertTrue($field->validate($validator));
     $field->setValue(false);
     $this->assertFalse($field->validate($validator));
     i18n::set_locale('de_DE');
     $field->setValue('12,00');
     $validator = new RequiredFields();
     $this->assertTrue($field->validate($validator));
     $field->setValue('12.00');
     $this->assertFalse($field->validate($validator));
 }
开发者ID:congaaids,项目名称:silverstripe-framework,代码行数:20,代码来源:NumericFieldTest.php

示例6: testEmptyValidator

 /**
  * Test empty values
  */
 public function testEmptyValidator()
 {
     i18n::set_locale('en_US');
     $field = new NumericField('Number');
     $validator = new RequiredFields('Number');
     // Treats '0' as given for the sake of required fields
     $field->setValue('0');
     $this->assertTrue($field->validate($validator));
     $this->assertEquals(0, $field->dataValue());
     // Treat literal 0
     $field->setValue(0);
     $this->assertTrue($field->validate($validator));
     $this->assertEquals(0, $field->dataValue());
     // Should fail the 'required but not given' test
     $field->setValue('');
     $this->assertFalse($field->validate($validator));
     $field->setValue(false);
     $this->assertFalse($field->validate($validator));
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:22,代码来源:NumericFieldTest.php

示例7: setValue

 /**
  * Set value of the {@link NumericField} because that is the actual value 
  * of the stock level. If unlimited stock is selected the value is -1.
  * 
  * (non-PHPdoc)
  * @see FormField::setValue()
  * @return StockField
  */
 function setValue($value)
 {
     $this->value = $value;
     $this->stockLevelField->setValue($value);
     return $this;
 }
开发者ID:helpfulrobot,项目名称:swipestripe-swipestripe,代码行数:14,代码来源:StockField.php

示例8: GameSignupFields

 public function GameSignupFields($reg)
 {
     $fields = new FieldList();
     $currentID = $this->getCurrentEvent()->ID;
     $event = Event::get()->byID($currentID);
     $prefNum = $event->PreferencesPerSession;
     $reg = $this->getCurrentRegistration();
     $fields->push(new HiddenField('RegistrationID', 'Reg', $reg->ID));
     $fields->push($fav = new HiddenField('FavouriteID', 'Favourite'));
     $fav->addExtraClass('favourite-id');
     $fields->push(new LiteralField('no-js', '<p class="js-hide">This page works better with javascript. If you can\'t use javascript, rank the items below in your order of preference. 1 for your first choice, 2 for your second. Note, only the top ' . $prefNum . ' will be recorded</p>'));
     for ($session = 1; $session <= $event->NumberOfSessions; $session++) {
         $evenOdd = $session % 2 == 0 ? 'even' : 'odd';
         $fieldset = '<fieldset id="round' . $session . '" class="preference-group preference-' . $prefNum . ' data-preference-select="preference-select-group">';
         $fields->push(new LiteralField('Heading_' . $session, '<h5>Round ' . $session . ' preferences</h5>' . $fieldset));
         $games = Game::get()->filter(array('Session' => $session, 'ParentID' => $currentID, 'Status' => true))->sort('RAND()');
         $i = 1;
         foreach ($games as $game) {
             $gameOptions = new NumericField("GameID_" . $game->ID, '');
             $gameOptions->setValue($i)->setRightTitle($game->Title)->setAttribute('type', 'number')->setAttribute('data-id', $game->ID)->addExtraClass('small-input js-hide-input');
             $fields->push($gameOptions);
             $i++;
         }
         // Add not playing option
         $gameOptions = new NumericField("NotPlaying_" . $session, '');
         $gameOptions->setValue($i)->setRightTitle("No game (or Facilitating)")->setAttribute('type', 'number')->addExtraClass('small-input js-hide-input not-playing');
         $fields->push($gameOptions);
         $fields->push(new LiteralField('fieldset', '</fieldset>'));
     }
     return $fields;
 }
开发者ID:helpfulrobot,项目名称:adrexia-gamesevent,代码行数:31,代码来源:GameSignupPage.php


注:本文中的NumericField::setValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。